Manage Large APK Expansion File - android

I'm using an expansion file (~500mb) that contains videos and more than 20.000 image files.
Which is the best way to manage this file?
For now, i'm loading the ZipFileResource object in my Application class when i check if this file is already downloaded.
One of the uses for this expansion file, is to provide images for a gigapixel view, but it takes a lot of time to load one image, and it should load about 30 images in 200ms.
Before i move this image files to an expansion file, there were in assets folder and worked well.
I'm planning unzip the expansion file at the external storage and remove the obb file, but i don't know if it's a good choice.
Can you tell me some advices?
Thanks in advance.

As far as I understood you, you'll download your mediafiles after you have installed the App. For this I would make it like that, download it and save it to the SD-Card (I would do this in an AsyncTask). Now you save every path of your picture or video into your DB. If you want to get the picture read it out the db and fill your ImageView or whatever. This way is really fast.
I hope I could help you.
safari

I tried to use Zip files as extension files once and I have found that they work very slowly.
OBB files works fast, just as with your regular file system.
I'm planning unzip the expansion file at the external storage and remove the obb file, but i don't know if it's a good choice.
It's bad choise. Google doesn't recommend:
To ensure proper behavior, you must not delete, move, or rename the expansion files.

Related

Using google play expansion files

I've just finished an app which is about 100MB and I need to use expansion files for the first time.
I've looked through this tutorial http://ankitthakkar90.blogspot.co.uk/2013/01/apk-expansion-files-in-android-with.html, but I don't understand the concept of expansion files and looking for a bit more clarification.
What exactly are the contents of these expansion files? For example my app using alot of images and videos are these what need to go in my expansion files.
If the above is correct does that mean I need to take them out of my project, change my code were I have referenced these resources directly from my drawables and instead reference them from memory?
If both the above are wrong then what exactly goes in the expansion files and what happens to the apk which is already over 50MB.
I'd really appreciate any help explaining this.
1) Expansion files can have any assets that you use in your app (videos,audio,images,text files etc).
2) Yes, your expansion files are extracted inside the external storage of the device.. you should update all your references to get the data from there.
http://developer.android.com/google/play/expansion-files.html
The above link has it all explained (naming to use, how to debug ) etc.

Overwrite Expansion File (Android)

My expansion file is 200 Mb. I can't see it viable to pull files out of it in realtime (too slow for my purposes). So, I'm extracting all of them to regular files in other folder.
Now, I want to save some space on the card for my beloved user by avoiding app data duplication.
I have an idea to delete the actual expansion file and replace it with a zero size dummy, to fool Google Play and prevent it from downloading 200Mb again. Would that trick work?
I can't test for that as my app is not published yet.
I have no idea what kind of data they look at in order to redownload the expansion file, but if you don't want to use it as intended I think you'll have an easier time hosting your files and downloading them through your own download mechanism.

Loading JPEG from RAW resources

I need 6 large images in my app. And I don't need the quality and alpha channel provided by PNG. Is there a way to embed JPEG files into the raw resource and unfold them into SD card at first launch of the program? It will save me 3-4 MB in my APK. Thanks!
It's very easy. Put your file in res/raw filder and use:
InputStream is = getResources().openRawResource(R.raw.image);
BitmapFactory.decodeStream(is);
You can simply open the stream and do whatever you want with the data.
I think I don't understand your question: It seems that you want to hive off image files at first run...
Anyway, I suggest to put the files in the assets folder and not in the resource. You can access the assets as a file system and copy them to any (permitted) location.
Have a look here:
Difference between /res and /assets directories
and here (look at assets):
http://developer.android.com/tools/projects/index.html
EDIT:
My answer suggests to use assets instead of the resources but, you can't modify your apk at runtime, look here:
how we can remove a file from the assets folder at runtime in android?
Nothing prevents you to put JPEG images in the resource folders, or in the assets folder if you don't need the R.drawable.MY_IMAGE thingy.
However, the images would still be included in your APK, and cannot be removed from your application package even after you copied them to the SD card.
The only way is to download the images separately from a web server on your application first launch.
The Google Play Store also provides some facility if your application needs big files, but that seems a bit of an overkill

How to secure downloaded images Android

I have to do some stuff. I'm downloading images using web-service, after successful download of each image, I'm using "AES" encryption algorithm to encrypt that images. I'have done encryption successfully. But whenever I'm going to open Gallery of device, I am able to seen that downloaded images encrypted by me. I don't want that. I wanna secure that images that can prevent access from Gallery.
I understood the whole process here.When I am storing each image after download Gallery capture that image and store into its cache so before my encryption process may be Gallery populate that images.
-> My Encryption process : Download Image - > Store into SDCARD - > Encrypting Image - > Delete the real Image
But this is not deleting from Gallery also.
So in short I wanna secure that images that can prevent access from Gallery. Let me know your best suggestion about my process is right or wrong? May I have to do a few changes on it? or have you nice idea instead of my process ?
Thanks for your best suggestions.
You must add an empty file to your images folder called .nomedia. This will prevent the MediaScanner from indexes images in that folder.
However, there is a bug on ICS that makes this slightly harder. On ICS, your folder must have the .nomedia present before you add images to it, or else the images will be indexed.
Another, slightly less compliant option is to begin your folder name with a dot (something like .foldername). As Android is UNIX based, this will make it a hidden folder, and hence not have the MediaScanner scan it.
I have got a proper solution. That will also work with higher versions.
You can keep it private with your application's private folder using following directory :
String mDirectory = getPackageManager().getPackageInfo("com.example.myapp", 0).applicationInfo.dataDir;
You can store your private data into this package. It will prevent access as well as prevent indexing from Gallery. So you don't need to worry about it's encryption process also :) . May be this folder will not provide much space. But atleast it will be help us.
Sounds like below solution might work for all versions -
(Storing videos, images and audio files that can not be accesses by others)
For this you have to store your data in External Storage with creating a folder name starting with the .(dot) then this folder is hidden from the FileExplorer.In this folder you need to create a .nomedia file and place your Images and video then images and videos are can not be visible to User in the Gallery.nomedia folder files can not be read by the gallery.

res/raw, assets or sdcard?

I am developing an app which is heavy on images, videos and other resources. What would be the proper place to store all this info? I can see that programmatically the raw folder is probably the easiest to handle, but what is the correct policy to this?
Assets is really bad place for items that are already compressed - when you build your app those will be tried to be compressed and this will have performance impact. Also in decompression.
Res / raw is a good way to go if you have the images in advance, especially if you do not wan to download them after launching the app, thus having the user to wait.
Sdcard should give you the most space. However, you will either need to download the resources from the net, I can not think of a way you ship them with the application and them move them to the sdcard. When you download the resources from the internet make sure you store them in a subfolder of:
private File getResourceFilePath(String ralativePath, Context context) {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
return new File(context.getExternalFilesDir(null), ralativePath);
} else {
return new File(context.getFilesDir(), ralativePath);
}
}
Otherwise you risk the resources being available in the Gallery of the user's device etc.
Keep in mind that if you store it in the res or raw folder it will be included in your apk file which will make your compiling and uploading to the play store longer and also make user downloads and updates from the play store take longer.
If the media is pretty static and over a few megs, make it a zip file that gets downloaded on the side and stored in a separate folder, that the user can pick. That way you can update the media separate from updating the application.
If you go down the zip file route, you should check out the APK expansion file support that google play has. http://developer.android.com/google/play/expansion-files.html
Note that if you use the expansion, other stores (Amazon, Nook, etc.) will still need the download a zip file support in your app.
-James

Categories

Resources