Android: Is EXTERNAL_CONTENT_URI enough for a photo gallery? - android

I'm playing around with Android's MediaStore classes and was attempting to create a very simple photo gallery app when I noticed that were two image content URIs: EXTERNAL_CONTENT_URI and INTERNAL_CONTENT_URI. At first I thought it was referring to the location of storage (external SD or internal memory) but after a bit of testing this was clearly not the case. I read more about it here, and it seemed to indicate that the internal content uri is actually content that are internal to each of the apps on the device. However I am not entirely sure and wanted opinions from more experienced developers who are more familiar with the MediaStore classes.
So my main question is, would just querying the EXTERNAL_CONTENT_URI be enough to get all of the important photos? And if possible to answer, what exactly is the INTERNAL_CONTENT_URI and what is it supposed to be used for?

External vs Internal storage doesn't refer to the location of the memory, but the privacy policy regarding it. Internal storage means only the app or system/super user processes can access the contents.
External storage can be read by every app, it's what appears when you plug in your phone to your computer, so you can think of it as what is shown to everyone else, hence "external."
I have a Samsung S5 for instance, and it puts both internal and external storage on the same 'internal' flash memory, they are in fact just separate partitions on the same stick of ram.
When I add a SD card, it adds another (secondary) external storage location.
Every android device must ship with internal and external storage, so devices that ship without an SD Card for instance are guaranteed to have partitioned 'internal' memory, for internal and external storage.
As for how the External_Content_URI relates, it will return images that are located in external storage -- reading the docs more closely, it says it returns only for the "primary" external storage volume. I just noticed that last part in quotes myself, so it's something I'll test in the next few days if secondary external storage is also indexed or retrieved by the mediastore, if someone else doesn't help answer that first.
http://developer.android.com/reference/android/provider/MediaStore.Images.Media.html

Related

Android Internal vs External Storage Confusion

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).

How to protect my app files being read/ write by other apps, in non-root device?

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.

Having private pictures in your Android app, which path is correct?

I am making an app where a user can take pictures, but I don't want them to be directly accessible outside the app. The user can choose to send a picture somewhere else if they want, but by default the pictures should be internal to the app only.
What is the correct way to do this? There are so many different path defaults in Android and I am not sure which I should be using (internal memory, external memory, internal cache, external cache, SD Cards, etc).
I am looking at this link here https://developer.android.com/training/basics/data-storage/files.html
It looks like internal storage via getFilesDir() is what I am looking for, correct? However pictures are also large files and I don't know if it makes sense to put them internal to the phone or if this is bad practice.
Per the Forget the Storage Permission talk, getFilesDir() is indeed the right location for private storage of user data.

External Storage distinction

My question is related to storing files on android devices. I want to store files created in an app to an SD, if it is mounted. The problem i am having is that the device I am using has a non-removable external storage unit. All attempts to find the SD card result in finding that external storage and the files being saved there. Is there a work around, or a way to get a list of the external storage's, or way to directly save to the SD card?
Android 4.4 offers getExternalFilesDirs() (note the plural name), which may be able to give you locations on removable media like an SD card, depending upon where it is located and how the manufacturer elected to interpret Google's rules.
Everything else on Android 4.4+, in terms of removable media, cannot be written to, except presumably via apps running with superuser privileges on rooted devices.
There is no support at all for anything beyond standard external storage on Android 4.3 and below. You will find various recipes online for trying to find other partitions that might represent removable media. These recipes are not supported, may not be reliable across all devices, and will not work on many Android 4.4+ devices.
Hence, I strongly encourage you to focus on standard external storage.

Android move to SD card behavior

I have an application that downloads most of the resources from the internet during run time.
Most of those resources are images.
I don't want the user to see those images in the gallery application or in any other application. This requirement is crucial to me since:
I'm tracking which resource was downloaded and which need to be download later.
All those resources would be meaningless to the user and would irritate him.
I don't want the user or any other application to delete those images
Note: I'm aware to the fact that rooted users can do what ever they want and I don't care that those user will mess up the app.
To fulfill those requirements I used the internal storage and it works exactly as I expected and as needed.
I do let the user to move my application to the SD card, But:
what is happening to all the files that I saved in the internal storage and to the DB?
Are they all moving to the SD card with the application? Do they stay in the internal storage?
I believe that they do stay in the internal storage, but I haven't found any documentation for it.
And after I'll understand the behavior it raise few other questions.
The only requirement that I have is that the resources would be downloaded from the internet and that the user won't see them in any other application. I don't really care where those files are being saved, I think that if the user decides to move the application to the SD card it is since he has lack of memory in the internal storage, therefor I should transfer all my resources to the SD card.
Can i save something on the SD card without those files to be public for all?
What is the best way to handle this situations?
What option do I have to handle this situation?
Can I know if the app is installed on the SD card or on the internal storage?
I would thank you all for all your insights and recommendations.
Regarding the images not being visible in the Gallery App, you should put a .nomedia file into the folder that contains your images. Example: image permissions (don't want them in gallery)
Regarding the app to SD feature, I also wanted to have info on the subject, so I cannot help you :)
Useful answer: https://stackoverflow.com/a/3687467/334493

Categories

Resources