AndroidDev
AndroidDev

Reputation: 189

How to access files under assets folder of other apk's?

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).

Upvotes: 15

Views: 51726

Answers (3)

Santosh
Santosh

Reputation: 611

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()));

Upvotes: 5

user1357696
user1357696

Reputation:

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

Upvotes: 2

Nermeen
Nermeen

Reputation: 15973

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);

Upvotes: 19

Related Questions