2

Since Android 11 restricts the freedom accesing the external storage, I've looked many solutions to convert following path which I receive from ACTION_OPEN_DOCUMENT_TREE intent: content://com.android.providers.downloads.documents/tree/msd%3A163975/document/msd%3A163975 to a path looking like this: storage/emulated/0/Downloads/TestFolder

Why do I need the absolute folder path?: The user can choose a folder, where the app will create a backup ZIP file each day. Since the user might forget which folder he selected, he should be read the absolute path of the folder he choose. content://com.android.providers.... is not really descriptive for the enduser.

According to some valid answers, android 10-11 prevent developers receiving the absolute path of a folder. Is that true?

Other solutions I tried executing without any success:

  1. Get Real Folder Path from Document Tree Uri
  2. Get Full Path From Uri
Savan Luffy
  • 440
  • 3
  • 12
  • There is no requirement for `ACTION_OPEN_DOCUMENT_TREE` to have anything to do with the filesystem. – CommonsWare Apr 03 '22 at 11:28
  • @CommonsWare so since it's not correlated the "conversion" is not really possible? – Savan Luffy Apr 03 '22 at 11:31
  • 1
    Correct. The Storage Access Framework is an abstraction around document stores. The filesystem is a popular document store, but it is not the only one. Cloud storage services, like Google Drive, offer Storage Access Framework support. You can get apps that extend Storage Access Framework support to SMB/CIFS file servers (think: Windows), FTP servers, etc. You can use `DocumentFile.fromTreeUri()` and `getName()` to get a "display name", but that is it. – CommonsWare Apr 03 '22 at 11:33
  • Why would you convert a content scheme to a path like /storage/emulated/0/Download/TestFolder ? Apparently you know the path at forehand. So you could use it right away. – blackapps Apr 03 '22 at 15:19
  • 2
    @blackapps cause I don't know the folder which the user selects. the user might not select the TestFolder. Maybe he selected a folder in the documents root folder like: /storage/emulated/0/Documents/XYZFolder/AdditionalFolder/TestFolder. I can't know that at forehand unfourtantly. – Savan Luffy Apr 03 '22 at 15:51
  • 1
    So when do you think the Android SDK developers will come up with code that allows the user to select a folder? Has there been an OS without folders in the 21st century? – Paul McCarthy Dec 13 '22 at 01:44
  • 2
    @PaulMcCarthy that's a good question. it's really frustrating what android does to developers.... – Savan Luffy Dec 13 '22 at 21:07

0 Answers0