我的应用程序会下载并解压缩文件到特定文件夹:
output = new FileOutputStream(realpath, true);
output.write(buffer, 0, bytesRead);
ZipFile zipFile = new ZipFile(realpath);
有了新引入的 ACTION_OPEN_DOCUMENT_TREE
意图,我想为用户提供选择该文件夹的选项。
在测试我的 onActivityResult
中接收到的值时,我得到了类似于 /tree/primary:mynewfolder
的路径,它并不是实际物理路径,如 /sdcard/mynewfolder
。
Uri treeUri = data.getData();
String sPath = treeUri.getPath();
Log.v("Path from Tree ", sPath);
我的解压方法需要真实路径:
ZipFile zipFile = new ZipFile(realpath);
我如何从Lollipop(API 21和22)提供的URI获取真实路径,例如/sdcard/mynewfolder
?