The problem: before android 10, we could use direct file access. With Android 10 Google pushed us to use SAF and Uri access. With Android 11 Google says "ok, you can access (some) raw file paths again". It's a bit a mess to design an app backward compatible. What I did between Android 9 and Android 10 is to change the file access, from direct access to SAF. Since my app needs all file access I just used the ACTION_OPEN_DOCUMENT_TREE
to the root directory. However with Android 11 it doesn't work anymore. There's a new permission MANAGE_EXTERNAL_STORAGE
but I'm sure Google will restrict the usage to some file manager so it's not an option.
Summary: is there any compat API to use the app in several android versions? What's the best strategy in this case?
Asked
Active
Viewed 664 times
2

greywolf82
- 21,813
- 18
- 54
- 108
-
Why not just check the version of the system and do respectively? You have your code for Android 10-. I would left it, write new logic for Android 11. + one if statement, and you are done. I would stick to my wrapper to deal with files - much more freedom. I don't know about combat API for files. It is really changing with each version and google leaves you to deal with it on your own. – RevakoOA May 29 '20 at 08:25
-
Not so easy as I said, I migrated all my code from files to uri to be compatible with Android 10 and backward compatible with previous versions. Now I have the problem that Uri access via Saf can't be used anymore, really a mess. – greywolf82 May 29 '20 at 08:31
-
Have a look at my answer here - https://stackoverflow.com/a/60917774/5550161 – HB. Jun 03 '20 at 10:12
-
Unfortunately it's not possible to set the legacy attribute to true if you already published the app with false :/ – greywolf82 Jun 03 '20 at 10:15
-
@greywolf82 Why can't you can add it in your next update? – HB. Jun 04 '20 at 10:00
-
Google policy, you can't revert from false to true, only true to false – greywolf82 Jun 04 '20 at 16:10
-
`Since my app needs all file access I just used the ACTION_OPEN_DOCUMENT_TREE to the root directory. ` At an update you still can select your folder if that is a subdirectory of the root directory. Also the gui enables the user to create new directories in root of external storage. – blackapps Aug 27 '20 at 12:21
-
@blackapps A specific subfolder is not an option – greywolf82 Aug 27 '20 at 18:08
-
Why not? What would you do in the root? `migrated all my code from files to uri ` ? I have no idea what you mean by that. `that Uri access via Saf can't be used anymore,`? I have no idea what you mean by that. – blackapps Aug 27 '20 at 18:25
-
`With Android 10 Google pushed us to use SAF and Uri access. ` I know SAF but what do you mean by Uri access? And arent you forgetting the MediaStore? – blackapps Aug 27 '20 at 18:27