I am making a application wherein when I download the file through my application it gets downloaded inside my application data space. I am doing this basically because the files downloaded will not be accessed by users as they can access it if its stored in sdcard or internal memory.
So my question is that I want to open the file when user taps on the file by any third party application.ie. when the file is downloaded it will pop to open or not.If tapped on open then it should open by some other 3rd party application.
for e.g. if i download abc.doc then it should ask me to open through various readers.
Is this possible to do? and if not what solution can i implement?
Does this require the device to root..?
I am doing this basically because the files downloaded will not be accessed by users as they can access it if its stored in sdcard or internal memory.
First, "internal memory" is "application data space", assuming "application data space" refers to file storage and not RAM. There are only two places that you can write to in Android: internal storage and external storage.
Second, users who want to can access your file even on internal storage, such as by rooting their device.
So my question is that I want to open the file when user taps on the file by any third party application.ie. when the file is downloaded it will pop to open or not.If tapped on open then it should open by some other 3rd party application. for e.g. if i download abc.doc then it should ask me to open through various readers.
You could elect to make the file be MODE_WORLD_READABLE when you create it using openFileOutput(). This may allow some third-party applications to access the file. Or, you could implement a ContentProvider to serve this file. Either of these will also allow the user to access the file (e.g., via "share" options in those viewer apps), which runs counter to your original aim.
The only way you can have a file that is not accessible by users except through your app is if your app is the one to view (or otherwise work with) the file. And, as I noted above, even then rooted device owners can still elect to get to the file.
Related
Trying to make some sense of this complete mess of scoped storage.
So I'm storing some files (logs) generated by App A inside the Download folder.
I'm using Mediastore/ContentResolver and no problems with that either for read or write access as long as it's from App A.
But then App B needs to read these files and here comes the problem.
Same way using Mediastore/ContentResolver but the files seem invisible for queries.
Download is supposed to be a Shared Storage, but files are indeed generated as -rw-rw--- which means no permission for others which could explaind why App B does not sees files from App A if they are not in the same group.
Would the Storage Access Framework method work around this?
Thi not tried it yet because poping system window's is definitely not something I wanted as a user experience for my App.
Thanks.
If the second app has 'all files access' with MANAGE_EXTERNAL_STORAGE it can also list the files of the first app.
Otherwise you can let the user of the second app pick those files with ACTION_OPEN_DOCUMENT of Storage Access Framework.
You better store your files in a sub directory as then second app can pick complete directory with ACTION_OPEN_DOCUMENT_TREE and list all the 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
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.
Im new to Storage Access FrameWork on Android.
I need to be able to access hidden files on an external USB drive plugged into Android using the Storage Access FrameWork.
Im wondering if its possible for an app to access hidden files stored on an external USB drive connected to Android.
It seems in order to access a file, Android must display a dialog box where the user picks a file, giving the app access to only that file.
So if the file is hidden, it will not get displayed in the list of file presented by android to the user, so then the user cant pick the file, then the app wont have permission to access that file.
Is this correct? Is there a way around it?
Thanks
If you are familiar with Storage Access Framework then you I assume you are using Intent#ACTION_OPEN_DOCUMENT which launches the system documents picker.
Instead, use Intent.html#ACTION_OPEN_DOCUMENT_TREE. Then you will receive a DocumentFile that represents the directory and you can use DocumentFile#listFiles to iterate through all the files including 'hidden ones'.
I have a document file stored in my application's data folder, which is a kind of private folder to the application. It is a .doc file. I have doc viewer application installed in the device. Now, how can I open the file with the Action_view intent. As the viewer application can't access file stored in my application data folder, it is throwing an error saying file can't be accessed. I have no interest to copy the file to phone public folders like sdcard. Is there anyway to open that doc file. Any clue on embeded apk in android.
Thanks & regards,
Suman
You can't do this directly. Either copy the file temporarily to the SD card (external storage) or set permission temporarily to WORLD_READABLE. There are no embedded APKs in Android, but if the viewer is available as library you can include it in your app. Of course the problem with changing permissions temporarily is that you don't really get notified when the user has finished viewing it, etc.
The whole thing begs the question: why is it a private file if it needs to be viewed by third party applications? If it is meant for the user of the device, there is not much point in hiding it from them...