No activity found to handle Intent - android.inten

2019-03-18 04:21发布

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>

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] }

I was just following developer docs of android. Any ideas what I might be doing wrong?

Edit: 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?

3条回答
不美不萌又怎样
2楼-- · 2019-03-18 04:59

Just cast your intent, like,

     Intent intent = new Intent("android.intent.action.GET_CONTENT");
    ((Intent)intent).addCategory("android.intent.category.OPENABLE");
    ((Intent)intent).setType("*/*");
查看更多
走好不送
3楼-- · 2019-03-18 05:17

Add a mime type, or simply intent.setType("*/*").

This seems to be a known issue. setType() is required.

Edit: 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/

查看更多
孤傲高冷的网名
4楼-- · 2019-03-18 05:19

To open all files add this line:

intent.setType("*/*") ;

and if you need to filter to display images add this line:

intent.setType("image/*");
查看更多
登录 后发表回答