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

天大地大妈咪最大 提交于 2019-11-26 12:47:04

问题


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


回答1:


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



回答2:


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



回答3:


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



来源:https://stackoverflow.com/questions/12387637/how-to-access-files-under-assets-folder-of-other-apks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!