Working with Raw Resources

Android also allows raw files in addition to arbitrary XML files. These resources, placed in /res/raw, are raw files such as audio, video, or text files that require localization or references through resource IDs. Unlike the XML files placed in /res/xml, these files are not compiled but are moved to the application package as they are. However, each file has an identifier generated in R.java. If you were to place a text file at /res/raw/test.txt, you would be able to read that file using the code in Listing 3–33.

Listing 3–33. Reading a Raw Resource

String getStringFromRawFile(Activity activity)    throws IOException    {       Resources r = activity.getResources();       InputStream is = r.openRawResource(R.raw.test ...

Get Pro Android 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.