为什么NotesList中的隐式意图无法通过活动的意图过滤器?

问题描述

| 样本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;
}
该内容的详细信息如下所示: 动作:无 类型:空 数据(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>
如果我将数据更改为:它不起作用
< data android:mimeType=\"vnd.android.cursor.dir/vnd.google.note\" / >
,可以用。 这让我感到困惑,因为根据意图过滤器:   包含URI的Intent对象   但没有数据类型(并且类型不能是   从URI推断)通过了测试   仅当其URI与   过滤器,过滤器也一样   没有指定类型。这将是   仅针对mailto之类的URI:和   tel:不参考实际数据。 notesList中的意图仅包含一个URI(content://com.google.provider.NotePad/notes)且没有数据类型,在我的第一个意图过滤器中,uri与意图的uri匹配,应该可以,但不能,谁能解释为什么? 谢谢。     

解决方法

您引用了正确的段落,它说:“只有像mailto:和tel:这样的URI才引用实际数据。”但是“ 3” URI绝对是指数据,因此必须指定类型。     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...