Android distribute files with app - android

When I complete the Android app I am developing I will want to distribute it so that about 300 image files are stored on the sdcard. Is there any way to do this within the usual automatic installation system? I don't want to hog the internal memory by including the files in res/raw.
I believe the app can now be built with an instruction to install on the sdcard so I suppose I could do that and include the files in res/raw but is there any limit on the number of files in res/raw?

If you didn't want to include the images you could utilize the APK Expansion Files mechanism:
http://developer.android.com/google/play/expansion-files.html
It will even save it to the sdcard.
Otherwise, you will either have to include the images or download them programmatically to the sdcard. As for the limits of the res/raw/assets folder I couldn't find any hard figures. The upper limit though would be the max size of the apk. You could always write a little script that would place 5k/10k/20k 1byte files and see for yourself on that upper bound. If the actual amount of files became an issue you could always zip them in the assets/raw and unzip them to external storage.
I have personally shipped an application for a client that had upwards of 500 images in the assets folder and it worked very well.

Related

Developing an Android project with large assets; installing to device always takes a long time

I'm working on developing an Android application in Android Studio. I have large files in the assets folder, so the 'install' step of the code -> build -> install -> run cycle takes a long time, and I mean several minutes (5 to 10).
What's the best way to reduce that time?
The only idea I have is to use smaller assets data while developing.
The thing is the assets don't really change that often.
Are there any other ways to have the assets "pre-installed" so they don't have to be installed over and over again as part of the app (at least just while developing)
The asset folder consists of one large sqlite file, plus a myriad of image and sound files, that all add up to over 500MB.
I found it a nice way to do it using "Expansion packs" and "Opaque Binary Files" as described here:
https://developer.android.com/google/play/expansion-files.html
https://developer.android.com/studio/command-line/jobb.html
Here's how I did it:
1) Move everything from the assets folder to somewhere else.
Of course you are free to keep things in assets, but in my case I can do without them.
2) Use the jobb tool to create an obb file from your assets.
Assuming your package name is me.name.app
jobb -d appAssets -o main.1.me.name.app.obb -pn me.name.app -pv 1
You might have to change -pv depending on your package version.
The naming chosen here main.1.me.name.app.obb is not arbitrary; it's what the Play Store will rename your file to when you upload it. See the File Name section of the docs.
3) Figure out where you should place your obb file. This is the path that Android will place your file in when the app is downloaded from the play store. I haven't deployed it to the play store yet so for all I know there could be some mistake in this step.
The path to the obb is described in the documentation as <shared-storage>/Android/obb/<package-name>/ where <shared-storage> can be obtained from Environment.getExternalStorageDirectory() and package-name is me.name.app as per our example, so the path to the obb would be:
Environment.getExternalStorageDirectory() + "/Android/obb/me.name.app/main.1.me.name.app.obb"
On my Android, the external store seems to be at "/storage/emulated/0/" but I would assume it could be different across devices.
Once you find out where the path should be, place your obb file there.
4) In your app, use StoreManager.mountObb to mount the obb to a new root path. Store this root path in a global object and use it across your application's code.
You have to go through your code and change any part that relies on the AssetsManager and change it to use regular file paths.
Your app (apk) file size is now much smaller but you still get to access your assets.

Files added to assets slows testing

I've added several thousand files to my assets and suddenly it takes a minute to start when debugging from eclipse. Is there a way to have it not recopy all the asset files over each time?
Is there a way to have it not recopy all the asset files over each time?
No, other than to don't put them in assets/, but instead access them in some other fashion (e.g., external storage).
Note that the Play Store has a 50MB limit on the size of your APK file, in case your problem is literally in the transfer time to the device or emulator.

How to provide some resource files for an android application?

I'm writing an android application, which user can download some image files from server. There image files will be stored in android mobile.
Now I want to put some of image files inside the apk file, that user can start the application quickly after installing. I found I can put them into assets directory, but the directory is read only. When user download other image files, I need to store them into another directory.
So there will be two directories to store the image files, but they are the same type.
Is there any good solution for this case?
Check out http://developer.android.com/guide/topics/data/data-storage.html#filesInternal for a listing of different places you can put data on Android.
You should put downloaded image files into one of three places, depending on your needs.
If the images are meant to be viewable by the user (e.g. downloaded photos), put them on the external storage. If they are meant to be user-interface elements or other crucial (but not user-facing) images, put them on internal storage. If they are meant to be cached for quick access but downloaded if necessary (e.g. temporary images like those found on a website), put them in the internal cache directory (Context.getCacheDir()).
If you don't have a lot of assets, you can copy them to the target location when your program first runs (e.g. check for the existence of a certain file, and create that file when you are done setting up). Then you only have to check one place (unless it's the cache dir, in which case you can't guarantee that the files will stick around forever).
If you have a lot of asset files, I would use a two-stage lookup: consult your downloaded image directory first (so you can override builtin assets, for example), then consult your assets directory. This is also flexible enough to allow you to make use of multiple storage locations should you find the need.

Android: how to store resources that may be updated at runtime

What is the best way to store sound files (ogg) that are distributed with the app and updated at runtime?
I am developing an app that includes a default set of sounds as resources (res/raw/*.ogg). These work fine for the defaults but I want the user to be able to update the set of sounds with recorded sounds and downloads from the Internet. The problem is that the resources are read-only and, I think, assets are also read-only. I don't know how to include files in the project so they can be updated at runtime.
I can have the defaults as resources and files added at runtime on internal storage or SD Card, but I would prefer to have all the files in one place with a single interface for accessing them. Is there a way to include files in the project so they are written to internal storage or SD Card when the app is installed? Or is there a better place to put the files?
Put your files in /asset directory when packaging the .apk file. At runtime copy those files in application's internal storage /data/data/<application_package_name>/files (If files are not to much sized, It useful when device has no external storage included). Also update the files in same location..

Start Android app with files on sdcard or somewhere in the filesystem

I making an application with phonegap/cordova where I need to keep a lot of files up to date. Some files (mainly images) will need to be erased in time, and some new ones will get downloaded. The thing is, in Android, to manipulate those files, it seems I need to have them on the sdcard; so I copy the files the app starts with from my assets folder to the sdcard. It just seems like a waste of memory space.
Do you know if is there anyway I can start with the app having those files the app starts with already inside the sdcard? or at least somewhere I can delete them later?
Thank you.
Files that are delivered to the device as part of your APK will be stored in a form that cannot be modified by your application (other than by updating to a new version of the apk).
If you copy the files out of the APK into the private internal storage area or the external storage area, those copies can be modified, but the originals inside the apk will remain.
The most efficient solution may be to not put these files in your apk, but have your app instead download them separately on the first run, using whatever mechanism you wanted to use to change them in the future.
(Some people object to this feeling that such files are less secure against unauthorized use, but as the contents of an .apk are trivial to extract this is not a strong argument. Needing to maintain a server to download from is a slightly more substantial objection.)
You do not need to store the files on the SD Card. Each app has its own internal storage that is not accessible by any other apps. For more information see the official docs: http://developer.android.com/guide/topics/data/data-storage.html

Categories

Resources