3

In this other question

How to use the new SD card access API presented for Android 5.0 (Lollipop)?

It is explained how to use the new API to access the "external SDCard".

But, how can I know the actual directory returned in the result activity?

I mean in function

public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
    if (resultCode == RESULT_OK) {
        Uri treeUri = resultData.getData();
        DocumentFile pickedDir = DocumentFile.fromTreeUri(this, treeUri);

......

How can I get the actual path where "Uri treeUri" points?

Thanks, Francis.

Community
  • 1
  • 1
Francis
  • 31
  • 1

2 Answers2

0

Use

FileUtil.getFullPathFromTreeUri(treeUri, this)

from

https://github.com/jeisfeld/Augendiagnose/blob/f24ddd7d3da4df94552ca0a9e658399602855a67/AugendiagnoseIdea/augendiagnoseLib/src/main/java/de/jeisfeld/augendiagnoselib/util/imagefile/FileUtil.java

to get the full path. Seperate the path using

final String[] seperated = treeUri.toString().split("\\/");

to get the current dir name.

Farasy
  • 304
  • 2
  • 8
0

You can't get the absolute path because the Documents API is designed to abstract this from you.

However, the treeUri does contain the relative path to the file. Try examining the Uri using Uri#getPathSegments()

Peter Tran
  • 1,626
  • 1
  • 17
  • 26