How we can use images from APK main expansion file?

百般思念 提交于 2019-12-01 14:43:47

Since one can get a stream from a zipResourceFile, one can use BitmapFactory to create images from them.

InputStream is = zipResourceFile.getInputStream("myFilePath.jpg");
BitmapFactory.Options bfo = new BitmapFactory.Options();
bfo.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap b = BitmapFactory.decodeStream(is, null, bfo);

Note that since decoding will take some time, you'll want to do this out of the UI thread.

dagalpin already given a way how to get as InputStream.

Read your HTML file and convert it to UTF-8 String.

and load as below.


// you can also load from an HTML string:
 String summary = "<html><body>You scored <b>192</b> points.</body></html>";
 webview.loadData(summary, "text/html", null);
 // ... although note that there are restrictions on what this HTML can do.
 // See the JavaDocs for loadData() and loadDataWithBaseURL() for more info.

I have not tested it. But it seems to be working.

Instead of only image name use expansionfiles/myFilePath.jpg

InputStream is = zipResourceFile.getInputStream("expansionfile/myFilePath.jpg");

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