I'm going to create an app for accessing the files from the Internet. I do not want to implement UI, but instead to make them visible from other file managers. So, I chose to implement a Document Provider. And I did it. On the next pictures you can see that I open "Files" app, find "My document provider" and can access its files.
However, it's an emulator. When I tried to use the app on my physical device I found that I have no ways to see document providers. I use Xiaomi Redmi Note 5 Pro (android 9.0) there is no "Files" app. I tested top ~20 File Managers from Google Play and even MIUI build in file-explorer, but none of them can show me my "My document provider".
I managed to see my documents provider only when tried to attach a document from Gmail app. But it's not what I need.
Questions:
am I right that Documents Provider is not what I need?
Am I right it's rather an ADDITIONAL way to share the files with other client apps which use Storage Access Framework (like Gmail, photo editor, etc), but was not designed to be used as the main method for accessing the files?
Am I right that I have to implement my own Activities with UI and full functionality of file explorer as a main approach for user to access his files? (like Google Drive app - it has both: own UI for managing the files and documents provider accessible from system picker)
UPDATED
Finally I've found a solution. As I understand standard application "Files" is build in to ANY device. However, probably, manufacturer "hides" this app and provides some analog. On MIUI it's some "File Manager". On many Samsung devices, as well as on Pixel 2 XL, it's "Google Files" app. None of them see document providers. Only "Files" app can.
The "Files" app is still accessible as an option when you use SAF (for example start an Intent with ACTION_OPEN_DOCUMENT). But still you are not able to launch that app standalone. However, you can download "Files shortcut" from Google Play. When open it, you can choose an app for which "Files shortcut" should work as a shortcut. I chose "Files" app and everything works (didn't work until I checked "remember my choice" option). On both, Pixel 2 and Redmi Note 5 I can see my document providers. It's a great news, since I do not have to waste time for creating UI!
P.S. Please note, what I described above is not taken from a reliable source. I used the phrase "hidden app" and the fact about pre installed "Files" on ANY device just based on my observation and understanding.
P.P.S Also, I found that on Pixel 2 in "Google files" app there is also a way to open "Files": Browse -> Other storage -> System traces. For some reason there is no "Other storage" button on Redmi Note 5.
I do not want to implement UI, but instead to make them visible from other file managers
You have no means of forcing other apps to do much of anything. In particular, you have no means of forcing a file manager to show things from your app.
Am I right it's rather an ADDITIONAL way to share the files with other client apps which use Storage Access Framework (like Gmail, photo editor, etc), but was not designed to be used as the main method for accessing the files?
Correct. A DocumentsProvider is for making documents available via the Storage Access Framework. A file manager could elect to show documents from the registered DocumentsProvider implementations on the device. In practice, I am not surprised that few file managers do this. You might consider contributing that feature to open source file managers.
Am I right that I have to implement my own Activities with UI and full functionality of file explorer as a main approach for user to access his files?
That is up to you. If you want your app to be guaranteed to do something for all of your users, having your own UI for traversing your collection of documents would be a good idea.
Related
I have read the Android docs, and I am not hopeful, but I thought I would give it a go anyways. Basically, the situation is that I have 2 apps. App A is a content manager that checks on a secured server for content files and downloads them to its storage on the Android device. App B (and any other apps that later may be needed) needs to view the content in App A's storage. Usually FileProvider would be the way I go, but there's a problem with that.
Many of the content files are HTML documents with relative links. FileProvider doesn't give access to every linked file to App B, so links are regularly broken. I am not sure, as it is not my project, if App A can be directed to download to a shared location either.
Is there a way to:
have App A grant what apps are allowed read access to its storage?
have FileProvider grant general read access to a directory and all its sub-directories?
anything else someone might think of to get App B to view the files App A downloads?
or is this, as I fear, currently not possible due to Android restrictions?
Thank you.
As long as both your apps (A and B) are signed with same certificate then you can share resources between each other. This is a common practice within a lot of apps available at play store.
https://developer.android.com/guide/topics/manifest/permission-element.html#plevel
https://developer.android.com/guide/topics/manifest/manifest-element.html#uid
I do not actually know what this is called. But I have seen app icons beside their directories in internal storage. I assume that it's some kind of association. I would like to know how to achieve this for a directory made by my app.
Here is a screenshot showing Telegram and WhatsApp doing what I want:
I am using the following to create a directory:
File(Environment.getExternalStorageDirectory(), "MyApp").mkdirs()
What else should I add to the above code?
What else should I add to the above code?
Nothing. And note that this code does not work on Android 10 (by default) or Android R+ (for all apps), as external storage has been locked down.
But I have seen app icons beside their directories in internal storage.
Note that from an Android SDK standpoint, you are looking at external storage. More importantly, you are looking at external storage through some app.
I would like to know how to achieve this for a directory made by my app.
There is nothing in Android directly for this. You will need to talk to the developers of the app that you used (where you see this icon) and ask what they are doing. It could be as simple as "see if there is an installed app with the same name as the directory" or "see if there is an installed launcher icon with the same name as the directory".
Because I have seen it all file managers I have used
That means that you have more people that you can contact to see what they are doing. Again, there is nothing in the OS for this. After all, if there were, I could write an app to associate my app icon with every directory, and others could do the same. Whatever these file managers are doing, hopefully it is based on information that apps cannot manipulate to somehow spam the association information.
My company has three different Android apps that provide functionality for sales reps. We opted to separate the apps into "modules" because not all reps need all the modules. Up to now we have been using a JSON file in a directory on the SD card of the devices to set some configuration data for the apps. However, it appears that with Android 10 and beyond this will no longer be possible.
Currently we use getExternalStorageDirectory() to access the SDCARD and then open a file inside a directory our app creates.
Since we want the file access to not be something the sales reps have any control over we want it to happen transparently. However it does not seem this will be possible going forward.
Will using a custom FileProvider or even a DocumentsProvider be a way to continue to share data between our apps?
Another question, although not as important, is, can we change the default location of the DB files our app creates as we do now in earlier versions of Android?
Thanks
Rich
I'm looking for a way to make my VR Android app (for Samsung Galaxy S7 and S9) able to write files to the SD card (e.g. by downloading a .zip file and unzipping it there).
The app is mostly going to be used by people, who don't know a lot about Android/smartphones and don't want to have to deal with anything complicated (not necessarily seniors but close enough), that's why I want to make it as easy as possible for them, which also includes making choices myself (and setting it up for them) instead of showing complicated dialogs.
Special requirements:
The files must not be deleted when the app is uninstalled - that's why I can's use getExternalFilesDirs() (Storage Volume).
The folder everything happens in has to be easily accessable, so the zip files can be transfered to the SD card on your PC too (instead of downloading them through the app in case they are too big) without having to go down a huge amount of levels and remembering a long folder path.
Using Storage Access Framework isn't a good alternative either because not only is picking folders nothing that's especially VR friendly but it also requires knowledge about folders most of the users simply won't have and/or won't want to deal with every time they open my app. But: If there was a way to only show this once (on the very first start after installing the app) and maybe even set the root folder to the folder I chose, so the users only have to hit "accept", that would be worth a try (unless there's an easier way).
Yes, I did set the android.permission.WRITE_EXTERNAL_STORAGE permission and also enabled the "force allow apps on external storage" developer setting but trying to write to the SD card still throws an "Access Denied" exception.
Are there any others ways to write to the SD card that are VR friendly?
Android introduced the Multiple Users feature in 4.2 (Jelly Bean MR1) and its documentation states:
From your app’s point of view, each user is running on a completely separate device.
And here is a quote from the Environment.getExternalsStorageDirectory() and getExternalStoragePublicDirectory() methods doc:
On devices with multiple users (as described by UserManager), each user has their own isolated external storage. Applications only have access to the external storage for the user they're running as.
Could it be true that there really is no reliable way to communicate data between users on a single device without using the network as mediator? I'm looking for solutions that don't rely on quirks of how the device's file system is laid out by a manufacturer. Also, for security, the sharing should be internal to my app.
Even if file sharing is indeed impossible, is communication via intents somehow possible?
There are use cases for this. Use Case 1: let's say I'm writing an input method app that requires a 100MB dictionary file. I'd like to code things so that if User A downloads this file, then User B can access it also without needing to re-download. Use Case 2: let's say I'm writing a fun Leave My Wife a Note app that allows User A to type messages that will appear next time User B logs in (without using the network).
This thread on a separate site proposes a solution, but their method seems undocumented and possibly unreliable. And there are a few other SO questions that have a title similar to this one but are actually discussing different topics.
OBB Folder (/sdcard/Android/obb) is used to share files and folder between the multi users. But OBB folder not shown in my second user (One plus 5 mobile). So I have tried to create an OBB folder in Android folder (/sdcard/Android/) in second user and "BOOM" it worked. Now i am able to access the shared files in second user. Try this trick if OBB folder not shown in your second user.
OBB files (stored in /sdcard/Android/obb) and used as expansion files in Google Play are shared between all users by design, as they are fairly large. If you Input method uses expansion files, the downloaded data will be shared automatically. You can send broadcasts to other users but that requires the INTERACT_ACROSS_USERS permission, which is reserved for system applications.
I also had the same question, and have tried various approaches such as using /sdcard/Android/obb but it does not work in Android 10. So I followed below approach, and I am able to copy files seamlessly between users.
Login to the User from where you would like to copy files from (lets call U1)
Run FTP Server using any application of choice like MiXplorer / ES Explorer etc... Note down the details of the port#, username, password etc... and point it to /sdcard
Switch user, to where you want to copy files to (lets call U2)
Install the FTP browser. If you use MiXplorer / ES Explorer, they will allow you to add a FTP share
Use ftp://localhost:2121 assuming the port is 2121, if not change it accordingly and add the FTP share
Open the FTP share and you can see all the files & folders of U1 here
Copy across to your heart's content !