Tuesday, October 15, 2013

How to open Assets files of Android app

The key class is AssetManager, use Context:getAssets() to get the AssetManager object.

To open a file:
InputStream is = context.getAssets().open("foo");


To open a binary XML file. Be notice the XML files under assets folder will not be complied into binary file, so you have to use AssetManager.open() for them.
XMLResourceParser parser = myContext.getAssets().openXmlResourceParser("xml");


And also can list all the asset files:
String[] list = myContext.getAssets().open("sample/foo");

No comments:

Post a Comment

Thrift fails on Windows - thrift failed error: The command line is too long.

Meet a thrift compiling failure on my project on Windows 7. Using Maven in IntelliJ so I choiced maven-thrift-pluging for thrift files. For ...