A number of separate, but related, questions concerning where to store downloaded content within my application.
I have an application that downloads content from a central server. This content is sometimes premium content, or at least content where the publisher does not want it freely distributed. I understand that the “external” storage is readily accessible whereas the “internal” storage is protected, unless the phone is rooted.
If the application is installed on the SDCARD (as mine is configured to be) then is the “internal” storage also physically on the SDCARD? Thus if my SDCARD installed application downloads, say, 100MB of content to internal storage then is it actually ending up on the SDCARD, or is it ending up in the device’s physical on-board storage?
If the application is installed on the SDCARD, and the “internal” storage with the downloaded content is on the SDCARD then is it physically stored in an open format or is it encrypted? I seem to remember reading that an application stored on an SDCARD is encrypted. Does this also apply to the “internal” storage?
(Deleted question about storing files in a single directory as Context.getDir() implies that a directory system can be created and maintained in the internal storage)
Is there a better approach?
Did a bunch of experimentation and came to the following conclusions with Android 2.2 on a Motorola Droid 2:
When an application is installed/moved to the SDCARD then it is stored as an .asec file in the hidden /.android_secure directory on the SDCARD. This is an encrypted and compressed file.
When the application creates data files in the "internal storage" they are stored within the internal memory of the device, not on the SDCARD.
The Settings / Manage Applications details dialog for the application has a value for "Data" - this is the amount of data the application is using within its internal storage, that is in the internal memory not on the SDCARD
The external storage does end up on the SDACRD under the /Android/data directory
Clearing the data from the Settings / Manage Applications details dialog does indeed wipe everything, which means that the installed application needs to have enough knowledge/logic to handle the "no data" situation.
My app is a download content app. What this all means to me is that:
There is little real value in storing my small app on the SDCARD given that the bulk of the storage it will consume on the phone will be in the device's internal memory. Except of course that its always good to allow the application to install on the SDCARD.
The installation package needs to be able to recover the user's downloaded content if it is wiped by the user.
The concept of storing a unique installation id in the internal memory works well until a user deletes the application's data and hence causes a new installation id to be computed. Thus to be able to remember what content has been downloaded to a device requires a user account on a central server that the user creates/logs into whenever the application starts from scratch.
Related
I'm new to Android and extremely confused about storage.
I have 4GB of internal storage on my Chromecast.
I plugged in a USB and formatted it as a storage device.
After that I enabled force push installs to external in the developer settings.
The drive name shows under the settings as USB Drive, however when I load File Commander App it's not showing at all.
When I used Termux and took a look at /mnt/sdcard/Android/obb to find a large OBB, it seems to be showing at exactly the same directory as /storage/shared/Android/obb.
So where exactly is internal storage and external storage?
How can I move files between them if I can't do so using File Commander?
In short, Internal Storage is for apps to save sensitive data to which other apps and users cannot access. However, Primary External Storage is part of built-in storage which can be accessed (for read-write) by the user and other apps but with permissions
Internal vs external storage is kind of a distinction that didn't go the way it was expected to go. I think originally it was meant to be phone storage vs SD drives, but it moved away from that. Now internal storage is special storage for an app held in phone memory. Its limited in size per app, but you should reliably be able to hold that amount. No other app can read this (unless your phone is rooted).
External storage is unlimited, but theoretically may be less reliable? You may also not be able to get any, if the device is out of space. But its not really removable anymore, so you can count on it staying there. It also is specific to your app and no other app can read it.
Then there's a few special folders in external storage anyone can access. Downloads, photos, etc. These work like external storage but data stored there can be accessed by other apps.
None of the app specific storage will show on file picker, because other apps don't have access. Unless you're rooted, in which case the rules can change. Or if you're using ADB and debugging.
As for where the actual folders are on disk- that can change depending on model. You can't depend on exact directory structure on Android. When you're writing a program that's why you use getFilesDir and getExternalFilesDir.
(If you're wondering why they still have a difference between the two- I don't know other than inertia. They've killed every difference between them, the little difference left may as well be killed to make programming simpler IMHO).
I was wondering, what is a good way, to prevent my app files from being read/ write to other apps, in non-root devices
Currently, I'm storing my data (images, audio, ...) in getExternalFilesDir
But, some of my users complain that, they are still able to see images in 3rd party gallery app.
I am not sure whether they are using root phone. So far, I cannot access my app getExternalFilesDir from Google Photo app.
Based on https://developer.android.com/training/data-storage, it seems that only getFilesDir will prevent other apps from accessing the files.
But, is it appropriate for an app to store user data file in getFilesDir? (My app is a note taking app which needs to store user attachment images, audio, ...)
From discussion of Android getExternalFilesDir vs getFilesDir() for big files , it seems like getFilesDir is not designed to store user data files?
I was wondering, what is a good way, to prevent my app files from being read/ write to other apps, in non-root devices
Store your data in internal storage (mostly getFilesDir() and getCacheDir()).
Currently, I'm storing my data (images, audio, ...) in getExternalFilesDir
The only reason to use that location is if you want the user to be able to use your content from outside of your app, whether via other apps or via an attached desktop computer.
In the long term, getExternalFilesDir() and getExternalCacheDir() will be off-limits to other apps — you will start seeing this on Android 11 in particular. However, it will take years for Android 11+ to dominate the Android device ecosystem.
But, some of my users complain that, they are still able to see images in 3rd party gallery app.
Such apps might be augmenting the MediaStore by scanning external storage for images.
But, is it appropriate for an app to store user data file in getFilesDir?
Yes. Everything should be in internal storage, unless there is a specific need for the user to be able to use the content outside of your app. Internal storage should be your default choice, with external storage or the Storage Access Framework being explicit choices made to go against that default.
From discussion of Android getExternalFilesDir vs getFilesDir() for big files , it seems like getFilesDir is not designed to store user data files?
Um, no.
A decade ago, internal storage and external storage were separate partitions, in part because external storage typically was implemented as removable storage (micro SD card). Since Android 3.0 in 2011, though, internal storage and external storage are almost always separate directories on the same partition. The primary distinction between the two is what processes could access the files, with your portion of internal storage being locked down to just your app, and external storage being accessible by anything.
On my Samsung devices I put a file in the /Download folder. When I select the file within my app (via a file browser), the file is called /storage/emulated/0/Download/myfile.db. This name is stored in my app settings.
At the start of the app the file should be opened. First the app checks if the file exists. In some cases, say once every 2 weeks, the file is said to be not existing! This happens also at my friends mobile since half a year.
Why is that happening? For years everything ran smoothly.
This code runs for 6 years. Of course I added the permissions stuff.
Your help is much appreciated!
You can't use the Download as an guaranteed storage place for your files. You should use the Internal storage for the app. This is what Google has written about the download folder:
This space is called external because it's not guaranteed to be accessible—it is a storage space that users can mount to a computer as an external storage device, and it might even be physically removable.
Here you can read more about the Internal storage and the External storage in Android.
Here is some more information about the Download folder from Google.
Caution: The external storage might become unavailable if the user removes the SD card or connects the device to a computer. And the files are still visible to the user and other apps that have the READ_EXTERNAL_STORAGE permission. So if your app's functionality depends on these files or you need to completely restrict access, you should instead write your files to the internal storage.
I want to store some media files(mp3) in either external storage (if available) or internal storage.
I've done some reading on the Android developer page and it says that by default only folders stored in internal storage are app-specific and cannot be accessed by other apps or the user.
However, since it may storage space might be limited on some devices, one may want to consider external storage. The issue with this is that other apps can access you folder and read its contents.
Is there a proper way of the files such that they are completely accessible only from my app regardless of whether they are in internal or external storage, preferably a method that doesn't involve encrypting the folder?
I want to track everything that apps store in phone memory/on sd card, so I can delete it if the app is uninstalled. Is this possible? If not, how can I get all the files from phone memory/sd card?
there is no way to "track" what your application creates, i think..
generally, the app stores data in the Cache directory, which is :
"<storage directory>/data/<your package name>/"
on a device which supports external storage, the "storage directory" is generally "/mnt/sdcard"
you can read the documentation to learn how to use the External storage to save files you create through your application.
I'd also like to point out that there is no way for you to know when your app is being uninstalled, so you can't delete the files before uninstall manually anyway,if that's what you intend to do. The android system itself removes the files stored in your cache directory, though.