Well, I searched and searched, and I didn't have the exact answer, or I missed it. I want my users to select a directory:
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, READ_REQUEST_CODE);
In my activity I want to fix the actual path, which seems impossible.
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode == RESULT_OK) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M){
} else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP){
Uri treeUri = intent.getData();
getContentResolver().takePersistableUriPermission(treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
DocumentFile pickedDir = DocumentFile.fromTreeUri(this, treeUri);
I selected the folder:
Device storage/test/
I tried all of the following ways to get the exact path name, but to no avail.
File myFile = new File (uri.getPath());
treeUri.getPath();
pickedDir.getName()
pickedDir.getParentFile()
Basically, I need to turn /tree/1AF6-3708:into /storage/emulated/0/or everything that each device causes a storage location in it. All other available options return /tree/1AF6-37u08:.
There are two reasons why I want to do this.
1) , . , , , , , . , , :
Device storage/Android/data/com.app.name/
2) 5.0 / , , -, . / , .
, , Mediastore, . - -, . . .