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!
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.
We are trying to create an app which will download eBook from server and store it locally on sdcard. We tried to DRM eBooks, after we download an eBook the DRM will take care of the security of the eBook. But later due to some reasons we left the DRM concept. Now I want to know whether we can store the eBook securely in the sdcard. The user cannot do any operations in the file other than viewing. Can we store the file in some other location where the user cannot view the file at all. In iOS we can download the file inside the Bundle itself, but for android???. We tried storing the pdf as a BLOB file in DB and tried to read it from there, in that case also we need to write the file and then read it. I am really confused on this Issue, can someone suggest me a good approach on how to proceed further. Any help would be really appreciable.
Personally I've avoid the SDcard given it's pretty much open to all apps, as #commonsWare mentions having it internal storage offers the Android app sandbox security.
Have you considered IOCipher from the excellent guys at the guardian project it's build on SQLCipher and it allow you to create a encrypted virtual disk. The part I love about it is that it's a clone of the java.io libraries so you should only have minimal code changes.
Files stored on the external storage are easy to read by other applications or from user's PC. You might need to encrypt your files if you don't want anybody else to get access. Well encrypted files can be places anywhere in the system without any risks of being read.
Storing files on the internal storage in your case does not sound good, because there are still too many devices out there with the limited amount of internal storage, where every megabyte counts.
Can we store the file in some other location where the user cannot view the file at all.
Not on external storage. You can put the book on internal storage, in which case only rooted device users would have access to it outside of your app.
i) keep the files encrypted which are important to you.
ii) decrypt the files and move to the internal storage during runtime.
iii) Access your files only from internal storage.
Following these things will keep your file and method calling safe as they are accessible only to internal storage.
Example:(access moved assets files from internal storage )
file:///android_asset/ => file:///data/data/com.test.exmple/files/"
You can also try tools like quixxi that do this for you transparently.
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
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