找不到处理Intent的活动 - android.intent.action.OPEN_DOCUMENT

yas*_*osi 17 android android-intent android-activity android-4.4-kitkat storage-access-framework

我正在尝试Android 4.4的存储访问框架

我开发了一个虚拟应用程序,它启动了活动开始的意图.

    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(intent, READ_REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)

我还开发了另一个虚拟应用程序作为文件提供程序.

        <?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>
Run Code Online (Sandbox Code Playgroud)

我已经实现了MyFileProvider类.

但是当我启动用户应用程序(触发意图的那个)时,我收到以下错误

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT cat=[android.intent.category.OPENABLE] }
Run Code Online (Sandbox Code Playgroud)

我只是关注android的开发者文档.我有什么想法可能做错了吗?

编辑:这是我最新的Manifest.我还需要MyFileProvider"扩展DocumentsProvider"的"正确"实现吗?我现在可以在函数中返回null吗?

hyp*_*d09 27

添加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/


小智 7

要打开所有文件,请添加以下行:

intent.setType("*/*") ;
Run Code Online (Sandbox Code Playgroud)

如果您需要过滤以显示图像,请添加以下行:

intent.setType("image/*");
Run Code Online (Sandbox Code Playgroud)