15

When we browse any apk we found there is one folder named assets. Now I want to access that folder programatically. so how should I proceed for that? (Input for the program will be apk file/just app name).

AndroidDev
  • 189
  • 1
  • 2
  • 7

3 Answers3

19

This will list all the files in the assets folder:

AssetManager assetManager = getAssets();
String[] files = assetManager.list("");

This to open a certian file:

InputStream input = assetManager.open(assetName);
Nermeen
  • 15,883
  • 5
  • 59
  • 72
5

If you want to access file from assets folder use the following code:

InputStream is = getAssets().open("contacts.csv");
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(is);
HttpContext localContext = new BasicHttpContext();
HttpResponse response =httpClient.execute(httpGet, localContext);
BufferedReader reader = new BufferedReader(new 
InputStreamReader(response.getEntity().getContent()));
YouneL
  • 8,152
  • 2
  • 28
  • 50
Santosh
  • 611
  • 2
  • 6
  • 24
2

For example: If you have the .ttf file in your assets folder: then you used like this:

Typeface font = Typeface.createFromAsset(getAssets(), "MARKER.TTF");

Here is link: http://developer.android.com/guide/topics/resources/accessing-resources.html#ResourcesFromCode

Deepzz
  • 4,573
  • 1
  • 28
  • 52