没有找到处理 Intent 的活动 - android.intent.action.OPEN_DOCUMENT [英] No activity found to handle Intent - android.intent.action.OPEN_DOCUMENT
问题描述
我正在尝试使用 android 4.4 的存储访问框架
I am trying my hand on Storage Access Framework of android 4.4
我开发了一个虚拟应用程序,它在活动开始时触发一个意图.
I have developed a dummy app which fires an intent on start of the activity.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, READ_REQUEST_CODE);
此外,我还开发了另一个虚拟应用程序,用作文件提供程序.
Also I have developed another dummy app which serves as the file-provider.
<?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.
I have implemented the class MyFileProvider.
但是当我启动用户应用程序(触发意图的应用程序)时,出现以下错误
But when I launch the user-app (the one which fires the intent), I get the following error
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT cat=[android.intent.category.OPENABLE] }
我只是在关注 android 的开发者文档.任何想法我可能做错了什么?
I was just following developer docs of android. Any ideas what I might be doing wrong?
这是我最新的 Manifest.我还需要对 MyFileProviderextends DocumentsProvider"有一个正确"的实现吗?我现在可以在函数中返回 null 吗?
Here is my latest Manifest. Also do I need to have a "proper" implementation of the MyFileProvider "extends DocumentsProvider"? Can I just return null in the functions for now?
推荐答案
添加一个 mime 类型,或者干脆intent.setType("*/*")
.
Add a mime type, or simply intent.setType("*/*")
.
这似乎是一个已知问题.setType()
是必需的.
This seems to be a known issue. setType()
is required.
你还需要添加android:enabled="true"
,注意你应该从值而不是直接引用它,以便只为>=kitkat启用它.所以 android:enabled="@bool/is_kitkat"
, <bool name="atLeastKitKat">false</bool>
在 /res/values/
和
在 /res/values-v19/
you also need to add android:enabled="true"
, note that you should reference it from values and not directly so as only to enable it for >=kitkat. So android:enabled="@bool/is_kitkat"
, <bool name="atLeastKitKat">false</bool>
in /res/values/
and <bool name="atLeastKitKat">true</bool>
in /res/values-v19/
这篇关于没有找到处理 Intent 的活动 - android.intent.action.OPEN_DOCUMENT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!