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
Related
I have created an Android Application, in that I am playing and downloading audio file from server. So when user download audio file from server he/she can't show that file in File Manager or any other media player like Gaana app.
How to make it possible?
Thanks,
Sagar.
You can save the files in Internal Storage Area. These files would be private to your app only.
Using getFilesDir() on any context provides absolute path to the filesystem directory where your internal files are saved. There in you can create directory. For more information refer here
You can use few approaches:
Download files into the private application's directory. No other apps will have access to those files. Pros of this approach is that is is the easiest way. Cons is that the inner storage might be limited in the device.
Download files saving them with incorrect file extensions. Pros: easy to implement, can save anywhere. Cons: files can be accessed, copied and renamed by any other app.
The same way as 2nd approach, but add some encryption to the files, so nobody except you can use them. This approach might require on-the-fly decryption.
I'm developing an ebook reader app for Android. The special books for this app are zipped files of some html/css/js/image/... files which are in a server and will be downloaded by the app. Each zipped file may have 1-5 MB and if extracted, a lot more than that.
I was wondering, regarding to android guidelines, where is suitable to
Put the zipped book files?
Put the extracted files when they are being used?
Well, if you actually need to save that data when app finishes, you should use sd-card, since it has more space, but if you only download image one time, just to show it on screen than use internal storage. Also consider your lowest API since that will be phone with least storage, and your app needs to work there as well as on new devices. Either way if you have to make several files while extracting data, use internal storage because it will be faster, and move it later to sd card if you actually need to save it.
I need to store a large number of audio files in my app (around 350/400 files ). Each file has an average size of 2MB. I really don't know where to store them. Should i use SQLite database ? external storage ? something else ?
There will be no update on these files, i just want to store them and then play them. Currently i have like 15 files in the res/raw folder and it's really slow at launching.
My question is similar to this one: How to store large number of Audio Files in Android? but i didn't get the answer.
Thanks
You need store in another place like the SD card. Google Play currently requires that your APK file be no more than 50MB. You need 800MB for my math.
Check this link:
http://developer.android.com/google/play/expansion-files.html
You should store them in the External storage directory, unless this app is for your personal phone, and you know you have enough space.
The reason is many phones produced in the past few years have virtually no internal storage space (e.g. my nexus S has 1g internal, 15g external).
As others have said, you would have to use an Expansion File to distribute via Google Play, and this is by default downloaded to an External Directory. You cannot move, delete, or rename these files. Thus, I don't think its possible to store them internally (unless you make a redundant copy).
If the files are zip, you can access the media in these expansion files directly (and that is the Android's recommended approach).
If you do unpack and copy the media, you should probably store the data as seperate files. There's a number of database concerns to look into if you store large blob data (e.g. gigabytes) in SQlite. You can use a database to store any metadata for your music, by associating it with the file name/location. But if you just want to just store music, the file system is enough.
If you want your music to be accessible by other apps, use the built in Android directory for music (code below), o/w store it under android/data/com.name.package.
public File getMusicStorageDir(String albumName) {
// Get the directory for the user's public pictures directory.
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_MUSIC), albumName);
if (!file.mkdirs()) {
Log.e(TAG, "Directory not created");
}
return file;
}
IMHO you MUST use sqlite DB, there aren't many other options.. Maybe you can think about cloud storage and streaming for play. But this will going to complicate stuffs. Try out the sql lite solution, here [ http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html ] you can implement it in a couple of minutes. Cheers!
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.
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