Expanding your horizons using expansion files for Android

If you came to this page you probably scanned the QR code from the presentation that I did at droidconNL 2012 in Amsterdam. Or perhaps because you are interested in using expansion files for Android. Maybe the almighty Google even brought you here.

No matter how you got here, at my presentation I promised that I would provide you with source code and the presentation itself. The presentation and source code should be able to help you to get your Android application to use expansion files.

On top of that I will provide you with interesting reads that are definitely worth a look. So here goes:

  1. The source code – ExpandingHorizons
  2. The presentation – Expanding your horizons using expansion files
  3. Application in Google Play Store is incompatible for some “compatible” devices‘ – A blog post about why my app wouldn’t show up in the Google Play Store. The reason we started using expansion files
  4. Android developer page about expansion files

Thank you all for being interested and reading about these important matters! Feel free to leave a comment. I will gladly help you to expand your horizons!

Posted on November 22, 2012, in Android, General, How-To and tagged , , , , , . Bookmark the permalink. 20 Comments.

  1. Dear Ali Derbane,

    After your talk at Droidcon I finally had time to try these expansion files myself. Your tutorial is very useful, but I would like to add that .mp3 files shouldn’t be compressed either, since this will give problems when trying to play them.

    Kind regards,

    Joris

  2. Hi Joris,

    In my talk I just mentioned not to compress video files since I used this in my example application. You are right in saying that .mp3 files should also not be compressed. To be more accurate it’s not just .mp3 but also different forms of audio and video files you should not compress.
    Some additional information on this can be found here http://developer.android.com/google/play/expansion-files.html#StorageLocation.

    Thanks for your feedback and hopefully others who might use this blogpost as a guide won’t suffer from headaches anymore when trying to compress audio or video files to use in an expansion file.

    @Joris: Did you succeed in using expansion files? Have you got any other insights that might be useful when telling people about expansion files?

    Kind regards,

    Ali

    • Hi Ali,

      Thank you for your response, I didn’t notice this bit of information about media files on the developers site when I first read it.

      I did succeed in using expansion files. Some things I noticed during the implementation:

      – Google messed up the folder structure for some of the necessary libraries, for example some projects had two /res/ folders. You will need to fix this before you can import them into Eclipse.
      – My activity for downloading the expansion files doesn’t show the download progress in the activity, only in the notification bar. Not really a big deal but I have to figure out why that doesn’t happen.
      – If I use JOBB for creating the .obb files I wasn’t able to use them. I ended up just putting everything in a .zip archive (adding them uncompressed) and renaming this .zip file to .obb
      – When downloading your app with expansion files from the Play Store, it will immediately download the expansion files along with the .apk. If you want to test the behavior for downloading the expansion files at run time, remove them manually from your phone and start the app.

      All the nest,

      Joris

  3. Hi Joris,

    I am happy that you succeeded in getting your first expansion file enabled application running.

    Feedback on your insights:
    – Indeed, google messed up the folder structure for some libraries. It is definitely worth mentioning this in any of my next presentations.

    – Some pointers on showing the user progress updates:
    — Check slide 21 of my presentation titled: “Hello ExpandingHorizons Continued (13/18)”.
    — The code in this slide can be found in the onCreate method of EHExpansionFiles.java. of the sample code
    — Make sure to properly implement the necessary methods of the IDownloaderClient. The one you are most likely interested in at the moment is onDownloadProgress.

    – I myself also used command line zip to create the obb files. I actually didn’t know about JOBB before you mentioned it. Thanks for pointing out the existence of this.

    – True. It’s also possible and maybe best practice to test this behaviour without publishing the app to the play store. Some tips can be found in the presentation if you will be doing this. If you need any specific pointers you know where to find me.

    Good luck with finetuning your app and I am curious to see if you get the progress indication working!

    Kind regards,

    Ali

  4. Haven’t worked with the information yet, but I really need this for my app and appreciate your efforts. Very rare information and pretty complex to get the stuff from Google itself, they always forget to deliver basic step-by-step instructions.

    • Hi Bart,

      Thanks for your message. I would say, just dive into the presentation and use the provided code to understand what i am talking about in the presentation. Apart from the information provided by me also make sure to read the tips that Joris provided a couple of comments back. They can definitely be useful.
      After having created something that will use your expansion file(s) I am very curious to know how it worked out and what your experiences were.
      Also let me know if you get stuck or have a questions.
      Soon I will be writing a blogpost on how you can update and deploy an application that uses expansion files. So check out our blog every now and again :)

      Kind regards,

      Ali

  5. Hi aderbane,
    Your post helps me a lot….:) .i like the way u explained and posted the details regarding expansions.
    I need to know one thing…My application is developed and i have given path of my resources from assets/ab/ directory. and nw my app is in stage where i cnt change path and everything from whole app. so is there any way to store my downloaded expansion into my application assets directory or other way to link them with expansion…?

    Thanks

    • Hi Androdev,

      First of all thanks for your message and nice to see that you among others like the way I explain things.
      It is impossible to write your expansion file (or any other file) to your assets folder since the assets folder is read-only at runtime.

      In my sample code/presentation you can see where the expansion files are stored when downloaded from the play store. I think it’s good practice to keep it there if possible.

      I think from reading your question it seems like you’ve got some assets that will be bundled along with the application but you also want to be using assets that are in the expansion file(s). If this is a correct assumption, what I suggest you do is create some code that you can use to get your resource either from the assets folder or if available from the expansion file(s). In my code I’ve provided two ways to use your files from the expansion file. These samples might come in handy when you create your code to get it working.

      I am curious to know when and how you get it working. Good luck with it in any case!

      Kind regards,

      Ali

  6. hi
    i read your presentation its very helpful but i just want the full source code of that ,because in some place in your presentation you asked to call the method lke requestpause ,requestcontinuedownload i’m bit confused because i’m just a amateur in android so i need the full sourcecode and thanks in advance

  7. Thanks for the source code .But if you see in my project where i m using video as well as image in the main expansion file ,So i knew to fetch the video file from the main expansion file through your tutorial thanks a lot for that .but i m struct with image file i,e my image are all in png format so i want to use the image file in my project from the main expansion file not from the patch expansion file ,
    so it would be such pleasure if you help me out from this

    Thanks in advance

  8. k now even i made my app to run through expansion file .But now my videos are not playing i,e i put 5 videos in main expansion file So can you tell me the source code for 5 videos to play from main expansion file since you had given the source code for one video

    Thank you

    • Hi Sohan,

      I am happy to hear that you are making steps in the right direction.

      In EHVideoPlayer.java I create a static variable called VIDEO_NAME. In the method startVideoPlayback in that same java file you see that I use setVideoUri that uses CONTENT_URI in combination with VIDEO_NAME.
      If you want to play a video with a different name then you need to make sure that you use another value of VIDEO_NAME so it will play the differently named video.

      I hope you get it working with these tips but I do think that a basic understanding of playing videos in Android would make it easier for you to get your application working.

      Good luck and kind regards,

      Ali Derbane

  9. Hello Derbane,

    Sorry i couldnt get you you mean i have create a static array for VIDEO_NAME
    to run a 5 videos from the main expansion file ?

  10. Hi ,
    First of all, thanks a lot for the post.

    I have been playing videos from the raw folder perfectly before I integrated the Expansion files.
    Now I am following your example for the integration. I am getting errors with

    Media player – prepareasync called in state 1 etc.
    I was testing it by pushing the .obb file manually.

    Can you guess what I am missing here.

    Thanks in advance
    rahul

  11. Hi derbane,

    i couldnt play your app video i,e video.mp4 when i try to change the name i,e instead of video.mp4 i gave play.mp4 .Even i changed the name in the expansion file also .

  12. Can you tell me the file name of the obb file? cause I can’t figure it out(I’m a newb and wanna skip the downloading code and jump into playing video from obb. I don’t wanna host the files on google server.)

    • Ali Derbane

      Hi Bhavesh,

      In slide 7 of the presentation that is part of this blog post you can see the path your obb file should be placed and the name the expansion file should be.

      Good luck and kind regards,

      Ali Derbane

  13. how did yo create your obb file

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 65 other followers