HOWTO获得与ACTION_OPEN_DOCUMENT_TREE意图真实路径。棒棒堂API 21安培; 22 [英] howto get the real path with ACTION_OPEN_DOCUMENT_TREE Intent. Lollipop API 21 & 22
问题描述
我的应用程序下载和解压的文件在特定文件夹:
My app downloads and unzips a file in a specific folder:
output = new FileOutputStream(realpath, true);
output.write(buffer, 0, bytesRead);
ZipFile zipFile = new ZipFile(realpath);
随着新推出ACTION_OPEN_DOCUMENT_TREE意图,我想提供用户选择该文件夹。
With the new introduced ACTION_OPEN_DOCUMENT_TREE Intent I would like to offer the user to choose that folder.
在测试中我的onActivityResult接收的值,我得到这样 A路径/树/主:mynewfolder
,这是不喜欢/ SD卡/ mynewfolder物理真实路径。
When testing the values received in my onActivityResult, I get a Path like /tree/primary:mynewfolder
, which is not the physical real path like /sdcard/mynewfolder.
Uri treeUri = data.getData();
String sPath=treeUri.getPath();
Log.v("Path from Tree ", sPath);
我的解压方法需要真正的路径:
My unzip method need the real path:
ZipFile zipFile = new ZipFile(realpath);
我如何获得真正的路径如/ SD卡/从提供的URI在棒棒堂(API 21安培; 22)mynewfolder?
How do I get the real path like /sdcard/mynewfolder from the provided URI in Lollipop (API 21 & 22 )?
推荐答案
从URI得到真正路径的过程是和以前一样,但有一点增加:
Process of getting real Path from URI is same as before, but with a little addition:
Uri uri = data.getData();
Uri docUri = DocumentsContract.buildDocumentUriUsingTree(uri,
DocumentsContract.getTreeDocumentId(uri));
String path = getPath(this, docUri);
的getPath()方法的中间方法的要点可以在这里找到:的getPath()
这篇关于HOWTO获得与ACTION_OPEN_DOCUMENT_TREE意图真实路径。棒棒堂API 21安培; 22的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!