【问题标题】:No activity found to handle Intent - android.intent.action.OPEN_DOCUMENT未找到处理 Intent 的活动 - android.intent.action.OPEN_DOCUMENT
【发布时间】:2014-01-29 11:19:32
【问题描述】:

我正在尝试使用 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 吗?

【问题讨论】:

  • 你的虚拟应用程序是否使用权限android.permission.MANAGE_DOCUMENTS
  • @SherifelKhatib - 实际上它没有该权限。但我添加并检查了。还是一样的错误。

标签: android android-intent android-activity android-4.4-kitkat storage-access-framework


【解决方案1】:

添加一个 mime 类型,或者只是 intent.setType("*/*")

这似乎是known issuesetType() 为必填项。

编辑:您还需要添加android:enabled="true",请注意您应该从值中引用它而不是直接引用它,以便仅为> = kitkat启用它。所以android:enabled="@bool/is_kitkat"&lt;bool name="atLeastKitKat"&gt;false&lt;/bool&gt;/res/values/&lt;bool name="atLeastKitKat"&gt;true&lt;/bool&gt;/res/values-v19/

【讨论】:

  • 成功了!但我仍然看不到作为提供者工作的我的主机应用程序。
  • 仍然无法看到作为提供者工作的我的主机应用程序。
【解决方案2】:

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

intent.setType("*/*") ;

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

intent.setType("image/*");

【讨论】:

    【解决方案3】:

    只要表达你的意图, 喜欢,

         Intent intent = new Intent("android.intent.action.GET_CONTENT");
        ((Intent)intent).addCategory("android.intent.category.OPENABLE");
        ((Intent)intent).setType("*/*");
    

    【讨论】:

    • 大量不必要的转换......你不妨写new Intent("android.intent.action.GET_CONTENT").addCategory(Intent.CATEGORY_OPENABLE).setType("*/*"); 并获得相同的结果,但操作要少得多
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 2022-11-29
    相关资源
    最近更新 更多