`

Intent及IntentFilter学习

 
阅读更多
隐式Intent理解
http://www.cnblogs.com/xirihanlin/archive/2009/07/31/1535609.html
http://blog.csdn.net/shmily_yang/article/details/5283694
http://hi.baidu.com/lfcaolibin/blog/item/87e66424c02f986b34a80f20.html

Android Intent Filter简单使用
http://bigcat.easymorse.com/?p=1454

http://blog.csdn.net/fenghome/article/details/5777855
http://blog.csdn.net/henanchina/article/details/5053691
什么是Intent
http://book.51cto.com/art/200908/142683.htm

定制android启动界面
http://blog.chinaunix.net/space.php?uid=20355083&do=blog&id=1963979

IntentFilter学习
http://www.apkbus.com/android-17556-1-1.html
http://www.cnblogs.com/Android_2011/archive/2011/06/12/2078643.html
引用
IntentFilter类
IntentFilter类表示Intent过滤器, 大部分情况下, 每一个component都会定义一个或多个IntentFilter, 用于表明其可处理的Intent.
一般来说, component的IntentFilter应该在AndroidManifest.xml文件中定义.
定义的方法: 在<activity>, <receiver>, <service>元素中增加一个或多个<intent-filter>子元素. 如:
<!-- 声明作为程序入口的Activity -->
<activity android:name=".FirstActivity">
        <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

IntentFilter与隐式Intent
android系统处理隐式Intent时, 会比较Intent和IntentFilter的action, data, category属性, 如果以上3个属性全都相符的话, 则IntentFilter所属的component就可以作为目标组件的候选(存在多个符合条件的component时).
1. 测试action属性. intent最多只能定义1个action, 而filter可以定义1个或多个action.
通过action测试的条件为: filter定义了intent的action. 例如intent的action为"android.intent.action.MAIN", 则定义了"android.intent.action.MAIN"这个action的filter都能通过action测试(当然, filter还可以包含更多额外的action).
如果filter没有定义action, 则这个filter将阻塞所有intent. 如果intent没有定义action, 那么只要filter定义了action就可以通过action测试.
2. 测试category属性. intent可以任意多个category, filter也可以任意个category. 通过category测试的条件为: filter定义了intent的所有category. 例如intent定义了"android.intent.category.DEFAULT"和"cn.xing.intent.category.UPLOAD"这2个category, 则定义了以上2个category属性的filter才能通过测试(当然, filter还可以包含更多额外的category).
根据上面的规则, 如果一个intent没有定义category, 则所有filter都可以通过category测试. 但是有一种例外: 以startActivity(intent)方式启动一个activity时, 系统为会intent增加一个值为"android.intent.category.DEFAULT"的category, 这就意味着每一个期望通过category测试的activity, 都要在其filter中定义"android.intent.category.DEFAULT"(除了作为程序入口的activity).
3. 测试data属性. intent最多只能定义1个data, filter则可以定义多个data.
通过data测试的条件为:
a. 如果intent没有指定data和data type, 则只有没有定义data和date type的filter才能通过测试;
b. 如果intent定义了data没有定义data type, 则只有定义了相同data且没有定义date type的filter才能通过测试;
c. 如果intent没有定义data却定义了data type, 则只有未定义data且定义了相同的data type的filter才能通过测试;
d. 如果intent既定义了data也定义了data type, 则只有定义了相同的data和data type的filter才能通过测试.
data属性是一个URI, URI中包含scheme, host, post和path, 典型的URI为:
scheme://host:port/path
scheme, host, post和path都是可选的. 比较2个data时, 只比较filter中包含的部分. 比如filter的一个data只是指定了scheme部分, 则测试时只是比较data的scheme部分, 只要两者的scheme部分相同, 就视为"相同的data".
分享到:
评论

相关推荐

    Android使用Intent和Intentfilter进行通信

    Android使用Intent和Intentfilter进行通信,源于《疯狂Android讲义》值得学习

    Intent和IntentFilter

    Android API指南

    Android组件间通信–深入理解Intent与IntentFilter

    Understanding Intent and IntentFilter–理解Intent和IntentFilterIntent(意图)在Android中是一个十分重要的组件,它是连接不同应用的桥梁和纽带,也是让组件级复用(Activity和 Service)成为可能的一个重要原因。...

    IntentMatcherDemo:Intent 和 IntentFilter 匹配规则案例

    要想使用隐式 Intent 成功启动 Activity, 必须保证 Intent 中 action、category、data 的设置和要启动的 Activity 的 IntentFilter 相匹配。这是一个 Intent 和 IntentFilter 匹配规则演示的小案例。 Intent 和 ...

    Android组件间通信--深入理解Intent与IntentFilter

    本篇文章是对Android组件间通信Intent与IntentFilter进行了详细的分析介绍,需要的朋友参考下

    android中Activity和Intent的关系

    主要讲解了android中Activity和intent的使用。适合初学者!

    Android Intent和Intent Filter详解

    Intents and Intent Filters  三种应用程序基本组件——activity, service和broadcast receiver——是使用称为intent的消息来激活的。Intent消息传递是一种组件间运行时绑定的机制. intent是Intent对象, 它包含了...

    Data、Type属性与Intent-filter配置

    Data、Type属性与Intent-filter配置首界面如图4所示,点击“查看图片”可以选择3个符合条件的Activity显示分别以全屏、图5和缩小三个不同的Activity显示图片。

    Android_Intent和Intent_Filter详解

    Android_Intent和Intent_Filter详解

    使用Intent filter来实现不同应用中Activity的相互跳转

    使用Intent filter来实现不同应用中Activity的相互跳转,点击A应用中的Activity,就跳转到B应用中的Activity,这种方式可以实现从一个应用的Activity 跳转到另一个应用的Activity,它们之间还可以传递数据。

    疯狂Android讲义源代码2

    第5章 使用Intent和IntentFilter进行通信 第6章 Android应用的资源 第7章 图形与图像处理 第8章 Android的数据存储和IO 第9章 使用ContentProvider实现数据共享 第10章 Service与Broadcast Receiver 第11章 多媒体...

    疯狂Android讲义源码

    第5章、使用Intent和IntentFilter进行通信 第6章、Android应用的资源 第7章、图形与图像处理 第8章、Android的数据存储和IO 第9章、使用ContentProvider实现数据共享 第10章、Service与BroadcastReceiver 第11章、...

    疯狂android讲义源代码.7z.001(共三卷)

    第五章使用intent和intentFilter进行通信 第六章android应用的资源 第七章图形与图像处理 第八章android的数据存储和IO 第九章使用contentProvider实现数据共享 第十章service与broadcastReceiver 第十一章多媒体...

    疯狂android讲义源代码.7z.003(共三卷)

    第五章使用intent和intentFilter进行通信 第六章android应用的资源 第七章图形与图像处理 第八章android的数据存储和IO 第九章使用contentProvider实现数据共享 第十章service与broadcastReceiver 第十一章多媒体...

    疯狂android讲义源代码.7z.002(共三卷)

    第五章使用intent和intentFilter进行通信 第六章android应用的资源 第七章图形与图像处理 第八章android的数据存储和IO 第九章使用contentProvider实现数据共享 第十章service与broadcastReceiver 第十一章多媒体...

    详解Android应用开发中Intent的作用及使用方法

    比如,有一个Activity希望打开网页浏览器查看某一网页的内容,那么这个Activity只需要发出WEB_SEARCH_ACTION给Android,Android就会根据Intent的请求内容,查询各组件注册时声明的IntentFilter,找到网页浏览器的...

    Intent filter 关于Action、Category属性详解源码

    Intent filter 关于Action、Category属性详解源码 对应的博客文章链接: http://blog.csdn.net/a13429921973/article/details/9271973

    Android解析Intent Filter的方法

    主要介绍了Android解析Intent Filter的方法,较为详细的分析了Intent解析的原理与相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下

    疯狂Android讲义(第2版)完整清晰版.part1

    第5章 使用Intent和IntentFilter进行通信 第6章 Android应用的资源 第7章 图形与图像处理 第8章 Android数据存储与IO 第9章 使用ContentProvider实现数据共享 第10章 Service与BroadcastReceiver 第11章 ...

    疯狂Android讲义(第2版)完整清晰版.part2

    第5章 使用Intent和IntentFilter进行通信 第6章 Android应用的资源 第7章 图形与图像处理 第8章 Android数据存储与IO 第9章 使用ContentProvider实现数据共享 第10章 Service与BroadcastReceiver 第11章 ...

Global site tag (gtag.js) - Google Analytics