找不到处理 Intent 的活动 - android.intent.action.OPEN_DOCUMENT
题
我正在尝试 android 4.4 的存储访问框架
我开发了一个虚拟应用程序,它在活动开始时激发意图。
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, READ_REQUEST_CODE);
我还开发了另一个虚拟应用程序作为文件提供程序。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.saf"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.saf.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="com.example.saf.MyFileProvider"
android:authorities="com.example.saf.documents"
android:exported="@bool/is_kitkat"
android:enabled="@bool/is_kitkat"
android:grantUriPermissions="@bool/is_kitkat"
android:permission="android.permission.MANAGE_DOCUMENTS">
<intent-filter>
<action android:name="android.content.action.DOCUMENTS_PROVIDER" />
</intent-filter>
</provider>
</application>
我已经实现了 MyFileProvider 类。
但是当我启动用户应用程序(触发意图的应用程序)时,我收到以下错误
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT cat=[android.intent.category.OPENABLE] }
我只是在关注 android 的开发人员文档。有什么想法我可能做错了什么吗?
编辑:这是我最新的清单。我还需要有一个 MyFileProvider“扩展 DocumentsProvider”的“正确”实现吗?我现在可以在函数中返回 null 吗?
解决方案
添加 mime 类型,或者简单地添加 intent.setType("*/*")
.
这似乎是一个 已知问题. setType()
是必须的。
编辑:你还需要添加 android:enabled="true"
, ,请注意,您应该从值引用它,而不是直接引用它,以便仅针对 >=kitkat 启用它。所以 android:enabled="@bool/is_kitkat"
, <bool name="atLeastKitKat">false</bool>
在 /res/values/
和 <bool name="atLeastKitKat">true</bool>
在 /res/values-v19/
其他提示
打开所有文件添加此行:
intent.setType("*/*") ;
.
如果您需要过滤才能显示图像添加此行:
intent.setType("image/*");
. 只是铸造你的意图, 喜欢,
Intent intent = new Intent("android.intent.action.GET_CONTENT");
((Intent)intent).addCategory("android.intent.category.OPENABLE");
((Intent)intent).setType("*/*");
. 不隶属于 StackOverflow