We developed two android applications, one that creates a folder with multiple files (.xml /.txt /.db) and another one that needs to access these files. Both application needs read and write authorizations to these files.
Before Android 11, we use to store these files in the app-specific external storage (Android/data/com...), the other app was able to read/write those files.
With Android 11 and enforcement of scoped storage, secondary app cannot access the primary app folder.
Is there any way of creating a "public" directory that store all shareable files ?
While searching, i found about the FileProvider component but i don't know if it will work despite scoped storage.
I'm aware of the new authorization MANAGE_EXTERNAL_STORAGE, but if i use this i'm afraid that playstore might reject my apps.
Despite all my researches, i didn't find a solution to my problem.
Thank you for your help.
On Android 11:
Make your own directory in one of the public directories like Documents, DCIM, Pictures, Alarms and so on, and put your files there.
Related
In my existing app(Android 10) I have a folder under /storage/emulated/0/<my_folder>. After looking to various sources on Google Developers I don't think that it's possible to longer access the /storage/emulated/0/<my_folder> directory under Android 11, because of the changes made in storage access permission.
Of course I can create these folder under Android 11 inside the so called "scoped storage" as mentioned by Google. But if a user updates the app from 10 to 11, how can I access the old folder for copying the files inside to the new folder inside "scoped storage" when I am on Android 11?
Or is there some other way to migrate this folder under /storage/emulated/0/<my_folder> safely?
With intent ACTION_OPEN_DOCUMENT_TREE you can let the user choose your <myfolder>.
For new installations use /storage/emulated/0/Documents/<my_folder> instead.
There is no reason to copy files or folders.
You can reclaim the permissions for your old app folder via SimpleStorage:
storageHelper.requestStorageAccess(
expectedStorageType = StorageType.EXTERNAL,
expectedBasePath = "<my_folder>"
)
Ever since Scoped storage introduction, you can no longer create your folders under root directory without special permission, I.E manage external storage, but i doubt play store will allow that access to your app if the core functionality isnt affected,
You can do one of the following
store your required files in respected folders [Recommended] (Documents for docs, DCIM for images/videos, Music for audio files and so on)
Require Permission to folder by open document tree intent (Last resort)
I am confused with the new app storage system in Android. I am not sure where my use case falls under and I need your help in telling me the right approach for this
My app captures images and generates pdf documents. Prior to Android 10, I used to store them in an app directory where the user can easily navigate to them through other files browsing app (like Files app on Samsung). In addition, these files can be accessed from within my app (so essentially read and write).
With the new storage, I am not sure how to accomplish the same thing. If I use the internal storage then user can't see them. If I use the media approach, well it seems it is only for Audio/video plus they will not be organized in a folder like I have them organized.
Am I missing something? How would I solve this problem?
Thank you
On an Android 11 device you can store your files in a subdirectory of the public Documents directory.
You can do that using classic File means or the media store or SAF.
Other apps can see them using SAF or the media store. Or with classic file means when requested all files access.
The user can see them using the default Files app on the device.
Android Q will introduce a new sandboxed filesystem for apps, Scoped Storage. This policy will be enforced on any apps targeting API>=29. How should a thrid-party file manager app get through this restriction and continue to work properly?
This question is meant to be generic for any apps that have some file-managing functionalities, like browsing, saving, loading, syncing, etc.
I believe your question is equivalent to: How app can get access to main phone storage (usually /sdcard)?
The answer is: ask user for access to the whole /sdcard using ACTION_OPEN_DOCUMENT_TREE action. That way your app can access /sdcard and all its subdirectories.
From https://developer.android.com/preview/privacy/scoped-storage#manage-groups-of-files :
File management and media creation apps typically manage groups of files in a directory hierarchy. These apps can invoke the ACTION_OPEN_DOCUMENT_TREE intent to allow the user to grant access to an entire directory tree. Such an app would be able to edit any file in the selected directory, as well as any of its sub-directories.
Using this interface, users can access files from any installed instance of DocumentsProvider, which any locally-backed or cloud-based solution can support.
There is also sample project on Github showing how it is done: https://github.com/android/storage/tree/228c8e0aa19586bfcf36318ddb191719537a45a4/ActionOpenDocumentTree
That's what "Files by Google" is currently doing on Android Q beta: https://www.androidpolice.com/2019/04/08/scoped-storage-in-android-q-beta-2-limits-how-apps-can-access-files/#1
I would like to know if it is possible to set the permissions of the files that my Android app writes on behalf of the user in the external storage folder (that is the common user folders that are accessible to my app like "Documents") so that those files are not writable by other applications that know where they are or explore the external storage folders to find them.
I mean, if my application has many installations and it becomes the target of malware apps, and it has a known user files folder, the malware could change or delete those files (json and other types like txt, doc). I would like that it is not possible by means of file permissions setting.
But note that the user has to be able to manage those files and also edit them.
Even my app sends intents so other apps edit them.
Is it possible?
That is not possible. If you do not want other apps to have access to the files, put them on internal storage, not external storage.
You can create encrypted storage with consistency checking instead of using permissions, what is not possible.
My application generates some .csv files while running and these files are placed inside Android File system. These files are accessible outside the application also(as i can open these files in text editor and modify...)
Now I want that only my application should be able to read/write into these files.
Please help me in achieving this.
Thanks a lot.
These files are accessible outside the application also(as i can open these files in text editor and modify...)
Presumably that means you are placing them on external storage.
Now I want that only my application should be able to read/write into these files
Place the files on internal storage. This will prevent ordinary Android users from accessing the files except via your app.
Owners of rooted devices can get at those files, and if you are concerned about that scenario, then do not create any files at all, as owners of rooted devices can get to anything.
Also see article here: http://developer.android.com/training/basics/data-storage/files.html
It informs about internal vs external storage as well as making data public vs private for your app.