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

4

3 回答 3

19

这将列出资产文件夹中的所有文件:

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

这将打开一个 certian 文件:

InputStream input = assetManager.open(assetName);
于 2012-09-12T11:58:14.280 回答
5

如果要从 assets 文件夹访问文件,请使用以下代码:

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()));
于 2012-09-12T12:11:37.760 回答
2

例如:如果您的资产文件夹中有 .ttf 文件:那么您可以这样使用:

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

这是链接:http: //developer.android.com/guide/topics/resources/accessing-resources.html#ResourcesFromCode

于 2012-09-12T12:01:05.693 回答