Writing and updating trees of files on shared storage

from the CommonsWare Community archives

At June 4, 2021, 6:55pm, johnd126 asked:

Hi,

Just joined: first post! :slight_smile:

I work for a company that creates digital signs using a variety of Android players and screens. Recently we received a demo screen that is using Android TV (Android 10).

We have a suite of apps that read and write to the same folder tree of files … each folder can contain xml, image files, mp4 files, etc. and which folder its in is important as well.

One of our apps monitors the content files in the background, comparing them to versions on the server and updating them as necessary while another app reads the files and displays them. Until Android 10 this has all worked swimmingly.

But, I haven’t found a method on Android 10 where my app can update files in the background without having to pop up some request to the user. Obviously, popping up a save dialog isn’t ideal on a digital sign… Or, at best I can create a file but I can’t then rename it, update it or delete it.

I’ve read through a quite a number of the commonware blog posts and browsed through the books and I haven’t seen any method where I can write/update/delete/rename files in the background that would be accessible to other apps.

Am I missing something? Is there a way to do this on Android 10?

Thanks,
John


At June 4, 2021, 11:46pm, mmurphy replied:

Ideally, that directory would be off of one of the ones that you get from Context, such as getExternalFilesDir().

You can do that easily, if you work with directories that you get from Context, such as getExternalFilesDir() (or even getFilesDir(), since it feels like users do not need independent access to these files).

If you are trying to work with other locations, such as the old Environment series of methods… you really need to switch that to use methods from Context on Android 11+. For Android 10, you should be able to keep using Environment methods, by having android:requestLegacyExternalStorage="true" on the <application> element in your manifest.

Alternatively, if you are putting a custom build of Android on these “players and screens”, you should be able to arrange to allow your apps to have full access to external storage. I don’t have direct experience in doing that, but I have talked to (and worked with) others who have.


At June 8, 2021, 8:24pm, johnd126 replied:

The entire suite of apps need access to the same folder tree of files so none of the Context. options are workable since they all seem to be single-app specific.

I am going to do some experimentation with the requestLegacyExternalStorage flag that you mentioned to see if I can get something to work on Android 10, even if it means having to modify every app.

I have some hope that the ’ MANAGE_EXTERNAL_STORAGE’ permission that’s being added to Android 11 will get us back to a situation where we are able to control our own files again.

Thanks for your input.


At June 8, 2021, 9:16pm, mmurphy replied:

Please understand that Android as an OS has two sweet spots:

It feels like your firm is trying to have the benefits of the latter without the investment. That means you’re going to be increasingly limited by the former, as Android continues to improve privacy and security. Using a stock consumer OS for digital signage is not a sustainable course of action, IMHO.

Assuming that your original solution involved WRITE_EXTERNAL_STORAGE, it should just work… for Android 10.

If your suite is being distributed through the Play Store, it would stun me if Google will let you continue distributing your apps and allow them to have MANAGE_EXTERNAL_STORAGE.

Even if your apps are sideloaded, you would still need to be able to get into the system Settings app to be able to grant the permission, and I don’t know how practical that will be given your environment.


At June 17, 2021, 1:47pm, johnd126 replied:

We’re way too small a company (like most software companies) to be creating our own hardware but we are allied with companies that do create hardware for digital signs (like Iadea and VIAtech) but even they either can’t or won’t make major changes to Android. I suspect that they don’t want to veer too far from normal Android or programmers would have a hard time creating apps for their players.

Our apps are not in the Play Store so we don’t have to be beholden to their policies. I’ve done some testing with the requestLegacyExternalStorage flag and it does work but, as you say, likely only for Android 10.

I do realize that Google is more interested in the billions of phone users than us fringe users but I’m sure us on the fringe still number in the millions!

Thanks for your input.


At June 17, 2021, 2:01pm, mmurphy replied:

That’s understandable, but it does pose some limits on what you’re going to be able to do.

You can try MANAGE_EXTERNAL_STORAGE, though the setup process for granting that permission might be icky, as I mentioned.