1

I have the following in my AndroidManifest:

<activity android:name="IntentChild"
          android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.EDIT" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="vnd.intent.cursor.item/intent_example"
              android:host="example.intent"
              android:path="intent_example"
              android:scheme="content"
        />
    </intent-filter>
</activity>

I launch the activity with

Uri uri = new Uri.Builder().scheme("content").authority("example.intent").appendPath("intent_example").build(); 
Intent intent = new Intent(Intent.ACTION_EDIT, uri); 
IntentExample.this.startActivity(intent);

But I get:

E/AndroidRuntime( 865): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.EDIT dat=content:// 
example.intent/intent_example }

What am I doing wrong? Also, does Uri.Builder.authority() refer to the same thing as the android:host attribute of the <data> tag in my manifest?

4

1 回答 1

0

在@A--C 的评论提示下,我最终添加了一个调用来Intent.setType()设置所需的 MIME 类型:

Uri uri = new Uri.Builder().scheme("content").authority("example.intent").appendPath("intent_example").build(); 
Intent intent = new Intent(Intent.ACTION_EDIT, uri); 
intent.setType("vnd.intent.cursor.item/intent_example");
IntentExample.this.startActivity(intent);

为简单起见,我还修剪了 my<intent-filter>以仅声明android:mimeType. 我猜想,但不完全确定,这并不像之前的变化那么重要。

<activity android:name="IntentChild"
          android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.EDIT" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="vnd.intent.cursor.item/intent_example"/>
    </intent-filter>
</activity>
于 2013-01-22T19:14:46.110 回答