Francis
Francis

Reputation: 31

SD-Card access API Android for Lollipop?

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.

Upvotes: 3

Views: 652

Answers (2)

Farasy
Farasy

Reputation: 304

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.

Upvotes: 0

Peter Tran
Peter Tran

Reputation: 1669

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()

Upvotes: 0

Related Questions