Robin Davies
Robin Davies

Reputation: 7817

Why does this Activity intent-filter fails to match the given Intent?

I'm having trouble declaring an Intent filter. Why does the following code not work?

The Activity as declared in AndroidManifest.xml:

    <activity
        android:name="com.twoplay.smb.SmbLoginActivity"
        android:label="@string/smb_login_activity_name"
        android:theme="@style/SmbLoginTheme"
        >
        <intent-filter>
            <action android:name="android.provider.action.DOCUMENT_SETTINGS" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="content"
                android:host="com.twoplay.netplayer.smb"
                android:mimeType="*/*" />
        </intent-filter>
    </activity>

The code to launch the activity:

    Intent intent = new Intent(DocumentsContract.ACTION_DOCUMENT_SETTINGS);
    intent.setPackage("com.twoplay.netplayer");
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setData(Uri.parse("content://com.twoplay.netplayer.smb/tree/share%2FLOTHLORIEN"));
    intent.setType("image/png");
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "Failed to view settings in application",e);
    }

When executed, startActivity throws the following exception:

android.content.ActivityNotFoundException: No Activity found to 
handle Intent { act=android.provider.action.DOCUMENT_SETTINGS 
cat=[android.intent.category.DEFAULT] typ=image/png }

By way of context, I'm trying to implement settings on a Document Provider document. The startActivity code is cut and pasted from google source for the Document Provider UI application, but run within a test activity of my own so that I can debug it . The Document Provider UI correctly shows a "Display in " menu, but clicking on the menu item does nothing, and there's no error visible in the UI although android core source suggest there should have been a Log.e call if the startActivity call had failed. The git archive states that the source for the Document Provider UI I was looking at was "Android 10 Release" (although it probably doesn't match whats on my device).

The target activity launches without problems when started by other means, so there's no obvious problem with the target activity. A breakpoint on Activity.onCreate is never reached when using the code given above. There are no errors or warnings in the log file. And no obviously relevant info or debug messages.

Running on Android Q.

Upvotes: 0

Views: 678

Answers (1)

Ali Rezaiyan
Ali Rezaiyan

Reputation: 3309

If you remove the type in both places, it would be fixed. But I don't know why it crashes when type defined.

Upvotes: 2

Related Questions