用户点击获取对话框的“打开方式...”并没有列出我的应用程序。 当我尝试打开文件时,我想获取它的绝对路径。我得到的是内容:// URI如何使用intent.action.VIEW打开文件时获取文件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();
}
}
但我想不是只读文件,我也想编辑文件并保存。 –
@PersonalJesus:在'ContentResolver'上也有'openOutputStream()'。督察,你会做一个绝对路径和同样的事情'FileInputStream' /'FileOutputStream'的东西,你可以用'content'做'Uri'和'openInputStream()'/'openOutputStream()'。 – CommonsWare