Can I create a DocumentFile with a stored Uri?

52 views Asked by At

I got a Uri using the following method.

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, MY_REQUEST_CODE);

likeļ¼š

content://com.android.externalstorage.documents/tree/primary%3A

Can I store this string to create a DocumentFile in application startup? like:

DocumentFile.fromUri(this,Uri.pasre(str))

It works on Android 6.0,but it seems invalid in higher version. Or I should get Uri every time I start it? I have found that some file managers do not need to get Uri via startActivityForResult(). Like RE. Are they using the shell to get a list under /storage and then stitching them into Uri?

Then use grantUriPermission() and takePersistableUriPermission() to get Uri permissions?

Sorry, my English is too bad. TT

0

There are 0 answers