2

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 Somehow I do not think that is going to work. Where do I put the main.1.com.redcricket.Album.obb file?

Red Cricket
  • 9,762
  • 21
  • 81
  • 166
  • Did you read [the documentation](http://developer.android.com/google/play/expansion-files.html)? – Ted Hopp Mar 18 '13 at 03:05
  • yes I have here: http://developer.android.com/google/play/expansion-files.html but I still do not understand what I am suppose to do. – Red Cricket Mar 18 '13 at 03:09

1 Answers1

1

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.

Community
  • 1
  • 1
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • Thanks Ted, I am still stuck. Where does the obb file go? I would like to test my app with the APK expansion modification before I upload it to google play. – Red Cricket Mar 18 '13 at 04:06
  • 1
    @RedCricket - To test the reading, just put the expansion file in the right place on your test device. To test downloading, you need to upload it (at least in draft form). This is also described [here in the docs](http://developer.android.com/google/play/expansion-files.html#Testing). If you're nervous about mucking with your existing app (I would be), you can upload a test app to check out the download logic. Set a license test response and everything should work. If you never publish the test app, you can eventually remove all traces of it from Google Play. – Ted Hopp Mar 18 '13 at 04:30
  • oh great now eclipse can't find Android SDK :( – Red Cricket Mar 18 '13 at 04:40
  • 1
    @RedCricket - My sympathies. I've had days like that. – Ted Hopp Mar 18 '13 at 04:42
  • Thanks Ted I will get it working again. But that will have to be tomorrow got to get some sleep now. Thanks for you help! – Red Cricket Mar 18 '13 at 04:51
  • Ah finally got eclipse fixed. now I can sleep :) – Red Cricket Mar 18 '13 at 06:33
  • Where do I put my APK expansion file? Looks like `getExternalStorageDirectory()` returns `/mnt/sdcard` so I guess that is where my App will look for the APK expansion file on my phone, after the App is installed. I need to know where I put my APK expansion file so that eclipse will upload to my phone when I am installing the App. – Red Cricket Mar 19 '13 at 02:54
  • 1
    @RedCricket - This is specified in the docs. It goes in the folder name that would be assigned to `loc` in the code I posted in my answer: `/mnt/sdcard/Android/obb//`, where `` is the name of your application package as declared in the manifest. The file name should be `main...obb`. – Ted Hopp Mar 19 '13 at 03:06
  • I guess I have to create those directories on my phone and manually copy the APK file to my phone. Before I install my App. Right? – Red Cricket Mar 19 '13 at 03:29
  • @RedCricket - Well, at least before you run your app. :) – Ted Hopp Mar 19 '13 at 03:42
  • Well hopefully this painful rewrite will discourage my completion that are selling similar products on google play :) Thanks for your help. I think I headed in the right direction now. – Red Cricket Mar 19 '13 at 03:54
  • Hey ... would you know why I get this error message `ZipResourceFile cannot be resolved to a type` I got this question asked http://stackoverflow.com/questions/15491559/zipresourcefile-cannot-be-resolved-to-a-type – Red Cricket Mar 19 '13 at 05:16