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

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?

The steps are pretty clearly laid out in the docs. In outline, the steps are:
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.
Rewrite the app to look for the expansion file in the location
Context ctx = getContext();
String loc = ctx.getExternalStorageDirectory()
+ "/Android/obb/" + ctx.getPackageName();
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.
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.

Related

How to create the expansion files in android

Hi guys I am new to android application. recently I am developing one application.It works well and fine. But my problem is application contains the audio's and sequence images(nearly 10000 images)by the end of the project apk size is 530 MB. how to create the expansion file for that project. i want to upload the project into play store. please guys anyone help me to create how the expansion files are created for that project.
I follow this website http://developer.android.com/google/play/expansion-files.html but I can not under stand properly. please any help me
An expansion file is typically just a zip archive of the things you want to have in it. Use your favorite ZIP tool to generate it.
Your expansion file name format should be : [main|patch]...obb
Gather all your contents inside a folder and rename the folder as per the naming format above and with .zip as extension.
For eg: main.1.com.your.packagename.zip.
Now you can upload this expansion file along with the apk.

Where can I find resource after installing an apk

I want to know how to find a resource in an apk after installing it. I mean, whether Android will extract the apk and save into file system after installing.
By now, I only know apk will is saved in /data/app. classes.dex can be found in dalvik-cache directory. But I don't find any clue about resource in this apk, such as string.xml, png or any file in assets. Is it possible that Android system unpack apk every time when it will use these resource?
I red many old thread, but I don't find answer yet. So can anyone please explain it for me?
Thanks very much in advance.
br
The resources are inside the apk file as binary xml files. Also after the installation. For simple xml files it will load them only from the apk file. Images and larger file might be cached, but I don't know exactly where.
only resources in res/raw folder will be available on device storage, otherwise it will be inside the apk as binary data
To explore an Android APK file,
[ View the graphics, play the audio, etc.]
all you have to do,
is right click on an APK file,
and set it to "Open With" to WinZip, Winrar.
or your favorite unzipper.
Thereafter, any time you click on an APK file,
you can view the graphics, play the audio,
view the resources, explore the programming, etc.
If you want to convert an APK file to Linux/Unix,
download "Dex2Jar" from
http://code.google.com/p/dex2jar/
then unzip one of the APK files
to a convenient directory,
navigate to the directory
and right click on the CLASSES.DEX file,
and set it to "Open With" "dex2jar".
Thereafter, anytime you click on an Android DEX file
this will convert the Android DEX file
to a Unix JAR file and put it in the directory
with the Android resources.
--
Tom Potter

Is there a difference between typical a ZIP file and an APK file?

I know a typical APK file would have AndroidManifest.xml but that's not the aspect I ask for. I'm asking in terms of ZIP structure and headers, i.e. at a lower level perspective.
Any APK file is a valid ZIP file. There's more to it than that - files that must be present, the fact that zipalign is normally used to align data structures within the file - but it's all valid ZIP.
AFAIK, it is a completely standard ZIP file. I have had no problems working with an APK as a ZIP file using any tool I have tried.
Note that, as with regular ZIP files, not all entries will be compressed (varies by file type).

Not A zip Archeive Expansion File

I am trying to use Expansion Files in Android. All source is givem in google extras . The only proble is that this code is not reading my .obb file.
How o create .bb file:
first i put my all resources in folder then made it .rar and from jobb tool i made this .rar file as .obb file. But when when i use it in my code the output says not a zip file
As i mention that i research on this topic alot but i did not come to the point so thats why i am asking this question
If your code expects a zip file, you should provide one instead of what jobb generates.
Put your files into a folder and use your favorite zip creator to generate a zip file. Put it onto the device with the correct name main.1.my.package.name.obb.

Is there a way to view the contents of a manifest file from an APK?

I saw here that someone listed the contents of the manifest of the official Facebook app's APK. Is there a way to decompile that, or is that info available elsewhere?
An APK file is just a JAR - change the extension to .JAR, and use a decompression tool to decompress it.
If you're using windows, you could just use WinRAR - that should decompress JARs.
In addition to that, a JAR is just a regular ZIP file - so you could technically just change the APK extension to .ZIP instead, and open it up using pretty much any decompression tool (as mentioned by Peter).
Here's some more info on JARs:
http://en.wikipedia.org/wiki/JAR_file

Categories

Resources