Android 为什么NotesList中的隐含意图可以';无法通过我活动的目的过滤器?

Android 为什么NotesList中的隐含意图可以';无法通过我活动的目的过滤器?,android,intentfilter,Android,Intentfilter,示例NotesList(由google提供,请参见此处:)显示了如何使用意图过滤器 在NotesList.java中,此活动创建一个选项菜单,菜单根据接受如下意图的可用活动添加菜单项: @Override public boolean onCreateOptionsMenu(Menu menu){ super.onCreateOptionsMenu(menu); // Create an Intent that describes the requirements to ful

示例NotesList(由google提供,请参见此处:)显示了如何使用意图过滤器

在NotesList.java中,此活动创建一个选项菜单,菜单根据接受如下意图的可用活动添加菜单项:

@Override
public boolean onCreateOptionsMenu(Menu menu){
    super.onCreateOptionsMenu(menu);

    // Create an Intent that describes the requirements to fulfill, to be included
    // in our menu. The offering app must include a category value of Intent.CATEGORY_ALTERNATIVE.
    Intent intent = new Intent(null, dataUri);
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);

    // Search and populate the menu with acceptable offering applications.
    menu.addIntentOptions(
         R.id.intent_group,  // Menu group to which new items will be added
         0,      // Unique item ID (none)
         0,      // Order for the items (none)
         this.getComponentName(),   // The current activity name
         null,   // Specific items to place first (none)
         intent, // Intent created above that describes our requirements
         0,      // Additional flags to control items (none)
         null);  // Array of MenuItems that correlate to specific items (none)

    return true;
}
此内容的细节如下所示:

<intent-filter android:label="hello filter">
                <action android:name="android.intent.action.INSERT" />
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:scheme="content" android:host="com.google.provider.NotePad"
                    android:path="notes" />
</intent-filter>
操作:空 类型:null 数据(uri):content://com.google.provider.NotePad/notes 类别:android.intent.Category.ALTERNATIVE

我希望我的活动包含在菜单中,我的活动的意图过滤器如下所示:

<intent-filter android:label="hello filter">
                <action android:name="android.intent.action.INSERT" />
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:scheme="content" android:host="com.google.provider.NotePad"
                    android:path="notes" />
</intent-filter>
它不起作用。如果我将数据更改为:
,它可以工作

这让我感到困惑,因为根据:

包含URI的意图对象 但是没有数据类型(并且类型不能为 根据URI推断)通过测试 仅当其URI与 过滤器和过滤器也一样 不指定类型。这将是 仅适用于mailto之类的URI:和 电话:这与实际数据无关

notesList中的意图仅包含URI(content://com.google.provider.NotePad/notes)没有数据类型,在我的第一个意图过滤器中,uri与意图的uri匹配,应该可以工作,但是没有,任何人都可以解释为什么


谢谢。

您引用了正确的一段,它说“只有像mailto:和tel:这样的URI才会出现这种情况,不会引用实际数据。”。但是
内容:
URI肯定是指数据,因此您必须指定类型。

实际上,如果我同时指定类型和URI,它将不起作用,相反,如果我只指定这样的mimeType:,它将起作用,这就是我感到困惑的原因。实际上,对于
content:
您不需要从docs()中指定类型:
但是,有时可以从URI推断MIME类型,特别是当数据是content:URI时,它表示数据位于设备上并由ContentProvider控制,这使得数据MIME类型对系统可见。
对于content:uri,应该从ContentProvider推断该类型