SD-Card access API Android for Lollipop?

 ̄綄美尐妖づ 提交于 2019-12-10 21:57:23

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/29646713/sd-card-access-api-android-for-lollipop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!