问题
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