码迷,mamicode.com
首页 > 其他好文 > 详细

Intent 匹配规则

时间:2016-06-09 13:31:02      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

 1.在AndroidManifest.xml中可以为 每个 Activity,Service 设置多个Intent-Filter;

 

 在系统启动和程序安装之后,android会收集AndroidManifest.xml 中配置的 Intent-Filter.

   每个intent-filter 从action category data三个量来过滤 intent.

  • Intent-Filter和Intent的设置规则

  1.每个intent-filter对象(这里是intent-filter不是 AndroidManifest.xml中的intent-filter的子节点,Activity 节点可以没有intent-filter子节点 可以配置 0-n个action, 1-n 个category , 0-n个data。IntentFilter 上的 data 节点上可以设置 scheme、host、port、path、mimetype 

  2.每个intent 可以设置 0-1个 action、0-n 个 category、0-1 个 data。Intent 上可以使用 Uri 设置 data,使用字符串设置 mimetype

  3.  在安装app的时候,intent-filter节点如果没有配置category,系统不会设置某个默认的category.

   如果在隐式启动activity的时候,startactivity(intent),系统会自动为这个intent在多匹配一次"android.intent.category.DEFAULT",所以如果要能够隐式启动activity,

  必须在AndroidManifest.xml中为activity配置"android.intent.category.DEFAULT",否则无论如何都不会匹配通过的。

 

 

  • Intent-Filter和Intent的匹配规则

   匹配步骤1,action 2, data  3,category

  action和category匹配规则:

        intent中的action必须在 intent-filter中设置了的

        intent中的每一个category必须在intent-filter中设置了的。

     data匹配规则

               data格式:<scheme>://<host>:<port>/<path> 

                从前往后匹配,intent中的data只需要和intent-filter中设置的部分匹配就可以了。

     比如  intent-filter中设置 <data android:scheme="test" android:host="www.google.com"/>

              那么

        Uri.parse("test://www.google.com:80"),

        Uri data = Uri.parse("test://www.google.com:88"), 

                      Uri data = Uri.parse("test://www.google.com")

               这三个都是可以匹配的。

      如果设置了mimeType ,那么intent中也要设置mimeType。

 

 

 

 

  

  

 

Intent 匹配规则

标签:

原文地址:http://www.cnblogs.com/hi0xcc/p/5571761.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!