我们如何能够从主APK扩展文件使用的图片?文件、图片、APK

2023-09-07 10:44:42 作者:隔岸观火

米最后2天面临的一个问题,我们如何可以上传在谷歌一个.apk文件播放其大小超过50MB然后我找到一种方法,从链接的 http://developer.android.com/guide/market/expansion-files.html 现在m,在最终会取得成功,但现在中号有问题,我怎么能在我的阅读对象从主扩展文件的文件就像是.obb格式

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

但是,现在能够从主扩展文件使用.mp3文件,如:

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

但是,我们如何使用从主扩展文件图像的WebView?

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

推荐答案

由于人们可以从一个子presourceFile流,可以使用BitmapFactory从他们创造的图像。

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

请注意,由于解码还需要一段时间,你会想这样做出来的UI线程的。

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