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

Enable HP Zbook Thunderbolt 3 Dock on Ubuntu

As mention in previously post, I installed Ubuntu on my HP ZBook. After two days used all things work just fine, but the Thunderbolt 3 Dock ...