0

In my app the user can select an existing file or just write a plain file path. Later the app uses the path to perform operations on selected file. I'm trying to study a strategy to face how filesystem access is changed in Android Q. I see two problems:

  1. I can't use anymore file paths or just use File interface but I need to use a Uri and I need persistent access to this Uri.
  2. Uri are not "predicatable", i.e. if the file doesn't exist at the moment the user can't select anything and it can't guess what will be the Uri (right?)

For point one I could use ACTION_OPEN_DOCUMENT_TREE with persistent read/write on the root to have access to all files, but I have no idea how to manage point two. To be noted that the file is not created by my app but it could be created later from another app and my app just use it. How can I manage point 2?

greywolf82
  • 21,813
  • 18
  • 54
  • 108
  • What does "just write a plain file path" mean? Do you mean that you are creating the content? Do you mean that you have an `EditText` where the user is typing in a path? Something else? In general, give the user options of "open document" and "new document" that map to `ACTION_OPEN_DOCUMENT` and `ACTION_CREATE_DOCUMENT`, respectively. – CommonsWare Aug 03 '19 at 10:59
  • just the user can write manually /storage/bla/bla/myfile – greywolf82 Aug 03 '19 at 11:06
  • I think that you will need to disable that option on Android Q and higher, sticking with `ACTION_OPEN_DOCUMENT` and `ACTION_CREATE_DOCUMENT`. – CommonsWare Aug 03 '19 at 11:08
  • it would be a huge limitation, my app is an automation app, it should be possible to work with files with a specific name (and path) in order to perform later operations. – greywolf82 Aug 03 '19 at 11:32
  • "it should be possible to work with files with a specific name (and path) in order to perform later operations" -- they can pick those locations using `ACTION_OPEN_DOCUMENT` and `ACTION_CREATE_DOCUMENT`. I mean, if typing in a path one character at a time is somehow essential, you could reject any path that does not wind up in `getExternalFilesDirs()`/`getExternalCacheDirs()`/`getExternalMediaDirs()`. That seems to be user-hostile. And you do not have filesystem access to anything else on Android Q (by default) or Android R+ (for all apps). – CommonsWare Aug 03 '19 at 11:52
  • I won't work because the files could be created by other apps, so it would work if the user move the file in the correct folder but for an automation app it's not possible to require to the user to move manually the file and it won't be possible for another app since the folders are now "private" for each app. What a mess Google. Moving from file model to uri model changes deeply the system, it won't be possible to perform the same actions like before :/ – greywolf82 Aug 03 '19 at 12:00

0 Answers0