【发布时间】:2017-06-15 12:15:13
【问题描述】:
用户在文件资源管理器中单击 .txt 文件并获得对话框“打开方式...”,其中列出了我的应用程序。 当我尝试打开文件时,我想获取它的绝对路径。我得到的只是 content:// URI
I/ActivityManager: START u0 {act=android.intent.action.VIEW dat=content://com.android.providers.downloads.documents/document/1031 typ=text/plain
如果我想检索文件的路径,我需要获取 file:// URI。我怎样才能只得到 file:// URI 而不是 content:// ?
这里是 AndroidManifest
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*"/>
</intent-filter>
这是我尝试处理文件的方式:
Intent i = getIntent();
String action = i.getAction();
String type = i.getType();
if (Intent.ACTION_VIEW.equals(action) && type != null) {
Uri uri = i.getData();
if (uri != null) {
Toast.makeText(this, uri.toString(), Toast.LENGTH_SHORT).show();
}
}
【问题讨论】:
标签: java android file android-intent uri