concept raw resource in category android

appears as: raw resources, raw resource
Android in Action, Third Edition

This is an excerpt from Manning's book Android in Action, Third Edition.

In addition to creating files from within your application, you can push and pull files to the platform using the adb tool, described in section 2.2.3. The File Explorer window in Eclipse provides a UI for moving files on and off the device or simulator. You can optionally put such files in the directory for your application; when they’re there, you can read these files just like you would any other file. Keep in mind that outside of development-related use, you won’t usually push and pull files. Rather, you’ll create and read files from within the application or work with files included with an application as raw resources, as you’ll see next.

5.2.3. Files as raw resources

If you want to include raw files with your application, you can do so using the res/raw resources location. We discussed resources in general in chapter 3. When you place a file in the res/raw location, it’s not compiled by the platform but is available as a raw resource, as shown in the following listing.

Listing 5.6. Accessing a noncompiled raw file from res/raw

Accessing raw resources closely resembles accessing files. You open a handle to an InputStream . You call Context.getResources() to get the Resources for your current application’s context and then call openRawResource(int id) to link to the particular item you want . Android will automatically generate the ID within the R class if you place your asset in the res/raw directory. You can use any file as a raw resource, including text, images, documents, or videos. The platform doesn’t precompile raw resources.