简体   繁体   中英

How do I change my code to use APK Expansion file?

My application is over 50MB because I use a lot of MP3 files. I typical do this ...

uri = Uri.parse("android.resource://red.cricket.RecordAlbum/" + R.raw.track_001_64kb );

... but if I have to use APK Expansion file I assume the above line of code has to change. But change to what? Any help is greatly appreciated!

Edit 1) Thanks for your answer Ted. I did create the expansion file like so:

red@ubuntu:~/android/workspace/Album/res/raw$ zip -n .mp3 main.1.com.redcricket.Album.obb *mp3

So what do I do now? rm -f *mp3; cd ../..; ant clean ; ant debug rm -f *mp3; cd ../..; ant clean ; ant debug Somehow I do not think that is going to work. Where do I put the main.1.com.redcricket.Album.obb file?

The steps are pretty clearly laid out in the docs . In outline, the steps are:

  1. Remove the .mp3 files from your .apk and put them in an expansion file. Name the expansion file according to the directions. The format of the file can be anything you want, but the docs suggest that for audio files you use an uncompressed ZIP format. Android includes the APK expansion ZIP library that can be used to load .mp3 files directly from a ZIP file without having to unpack it.
  2. Rewrite the app to look for the expansion file in the location

     Context ctx = getContext(); String loc = ctx.getExternalStorageDirectory() + "/Android/obb/" + ctx.getPackageName(); 
  3. Write code so that if the file is not there, your app will download it from Google Play, using the Application Licensing service as described in the docs. There's quite a bit of coding and configuration involved in this step.

  4. Access the .mp3 file(s) you want using the APK expansion ZIP library. The docs have examples of loading an MP3 from an expansion file by calling MediaPlayer.setDataSource() with a file descriptor, an offset into the ZIP file, and a file length.

Also see this thread for more details on how to do all this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM