几句简短的IntentFilter匹配规则总结

来源:互联网 发布:武汉云优化科技公司 编辑:程序博客网 时间:2024/05/01 17:14

IntentFilter的主要标签:

1. <category>

2. <action>

3. <data>

以下几句简单的话帮助记忆:

<category>

1.主菜单进入必须使用 <category android:name="android.intent.category.LAUNCHER" />

2. 接收隐式Intent必须使用 <category android:name="android.intent.category.DEFAULT" />

<action>

主菜单进入必须使用

<actionandroid:name="android.intent.action.MAIN" />

对于隐式的Intent必须指定Aciton

<data>

URI的内容组成:

    scheme://host:port/path

例如:

    content://com.fx.demo:200/system/etc

    http://www.google.com/getDetails?id=123

主要标签

<data android:host="string"
      android:
mimeType="string"
     
android:path="string"
     
android:pathPattern="string"
     
android:pathPrefix="string"
     
android:port="string"
     
android:scheme="string"/>

IntentFilter匹配隐式Intent规则

第一步、匹配ACTION

第二步、匹配Category

第三步、匹配Data

1、没有dataIntent只能匹配没有dataFilter;

2、只有URI没有数据类型的Intent只能能匹配只有 URI没有数据类型的Filter;

3、没有URI只有数据类型的Intent只能能匹配没有URI只有数据类型的Filter;

4、 URI和数据类型都有的Intent能匹配:

    ①只有相同数据类型的Filter
    ②只有相同URI的Filter
    ③URI和数据类型都相同的Filter

注:如果Filter没有指明scheme,默认支持:content:file:

0 0
原创粉丝点击