How we can use images from APK main expansion file?

允我心安 提交于 2019-12-01 14:03:37

问题


m facing a problem from last 2 days that how we can upload a .apk file on Google play having size more than 50Mb then i find a way to upload a .apk with APK Expansion File from link http://developer.android.com/guide/market/expansion-files.html now m succeed at end but now m having problem how can i read file from that main Expansion file in my object like it is in .obb format

But now able to use .mp3 files from main expansion file like:

AssetFileDescripto assetFileDescriptor = zipResourceFile.getAssetFileDescriptor( 
  "assets/all_types_of_people1.mp3");
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource( assetFileDescriptor.getFileDescriptor(), 
  assetFileDescriptor.getStartOffset(),assetFileDescriptor.getLength());

But how can we use images from main expansion file to WebView?


回答1:


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.




回答2:


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.




回答3:


Instead of only image name use expansionfiles/myFilePath.jpg

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



来源:https://stackoverflow.com/questions/10738818/how-we-can-use-images-from-apk-main-expansion-file

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