Android Marshmallow API 25 and below - EXTRA_INITIAL_URI not honored therefore unable to open given folder

260 Views Asked by At

when trying to use the now-not-optional-anymore SAF (Storage-Access-Framework) to access a given folder on older Android (Marshmallow API 25 or before) the EXTRA_INITIAL_URI is not honored, therefore not showing the requested folder uriToLoad but the generic Recent file manager, therefore making the life of users impossible.

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.putExtra("android.content.extra.SHOW_ADVANCED", true);
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, uriToLoad);
startActivityForResult(intent, REQUEST_CODE);

Any hint on how to open a given folder on such APIs <= 25?

thanks nicola

enter image description here

1

There are 1 best solutions below

0
KeyonZh On
uriToLoad = DocumentFile.fromTreeUri(context, parsedUri)

parsedUri = Uri.parse("content://com.android.externalstorage.documents/tree/primary[urlEncoded_content]")

urlEncoded_content = UrlEncode(":path")

path is relative path to sdcard root.