你好,我正在使用以下意图在安卓中选择任何文件:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);
我正在为选定的文件获取Uri,并通过调用
uri.getPath()
方法获取文件路径。在获取路径后,我使用file = new File(new URI(filePath));
创建文件对象,但我会收到IllegalArgumentException:URI不是绝对的
。为什么会这样?如何获取绝对路径?是否有其他选择可以使用Intent选择任何文件,然后Uri?在Android调试器中,uri对象显示为(来自下载):
content://com.android.providers.downloads.documents/document/67
;而uri.getPath()
给出的是/document/67
。
filePath
的值,还有为什么要使用File(URI)
构造函数? - pskinkUri
? - pskinkContentResolver#openInputStream(Uri)
。 - pskink