How To Open A Particular Directory Using Uri?
Solution 1:
I want to open a particular directory where images saved by my app are stored
Android has never really supported this.
I can get the Uri of that directory by Uri.parse(imagesDir.getAbsolutePath()).
That is an invalid Uri
. At best, use Uri.fromFile(imagesDir)
.
This is how my code looks as of now
ACTION_OPEN_DOCUMENT
does not take a Uri
in the "data" facet.
The closest thing to what you want is to add EXTRA_INITIAL_URI
to the Intent
. However, this is only documented to work with a Uri
that you previously obtained from ACTION_OPEN_DOCUMENT
or ACTION_OPEN_DOCUMENT_TREE
. It is unlikely to work with a Uri
from some place else, such as from some File
.
Solution 2:
SAF is pain. Uri.fromFile(file.getAbsolutePath())
doesn't work because returns uri likes file://sdcard...
. But DocumentsContract.EXTRA_INITIAL_URI
works with content
. Below works for me:
privatevoidselectDir() {
Urid= Uri.parse("content://com.android.externalstorage.documents/document/primary:Download");
Intentintent=newIntent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, d);
startActivityForResult(intent, PICK_WDI_FILE);
}
Post a Comment for "How To Open A Particular Directory Using Uri?"