android中intent-filter的分析和具体使用用例
来源:互联网 发布:研究生小论文数据造假 编辑:程序博客网 时间:2024/05/22 14:27
意图过滤器(intent-filter)由清单文件中的元素定义,嵌入在相应的应用组件里(例如元素),在元素里,你可以使用这3个元素中的一个或多个来指定接收的意图类型:
<action>在name属性里,声明接收的意图操作,值必须是操作的纯字符串,不是类常量
<data>使用一个或多个属性来声明接收的数据类型,他们表示数据uri,和MIME类型的各个部分
<category>在name属性里声明意图分类,值必须是操作的纯字符串,不是类常量
注意:为了接收隐式意图,必须在意图过滤器中包含CATEGORY_DEFAULT分类,startActivity()和startActivityForResult()方法认为所有意图都包含了CATEGORY_DEFAULT分类,如果你在意图过滤器中没有声明这个分类,那么没有隐式意图会解析你的活动。
意图过滤器的完整使用示例:
<activity android:name=".MainActivity"><!-- 将其标记为主活动--> <intent-filter> <category android:name="android.intent.category.LAUNCHER" /> <action android:name="android.intent.action.MAIN" /><!-- action.MAIN表明操作是主入口点,不期望任何意图数据--><!-- category.LAUNCHER表示应该放到系统应用启动里的活动图标,如果该元素没有用icon属性指定图标,那么系统用该元素图标--> </intent-filter> </activity> <activity android:name=".SecondActivity"><!-- SecondActivity实现一些文本数据,多媒体文件等操作--> <intent-filter> <category android:name="android.intent.category.DEFAULT" /> <action android:name="android.intent.action.SEND" /> <data android:mimeType=”text/plain”/> </intent-filter> <intent-filter> <!-- 再设置一个意图过滤器用来处理一些视频,图片等媒体数据--> <category android:name="android.intent.category.DEFAULT" /> <action android:name="android.intent.action.SEND" /> <action android:name="android.intent.action.SEND_MULTIPLE" /> <data android:mimeType=”application/vnd.google.panorama360+jpg”/> <!-- 注意,MIME类型,application/vnd.google.panorama360+jpg,是指定全景相片的特定数据类型,可以使用谷歌全景API来处理它-> <data android:mimeType=”image/*”/> <data android:mimeType=”video/*”/> </intent-filter> </activity>
注意:为了让活动出现在应用启动里,action_MAIN和category_LAUNCHER必须配对在一起,如果只有一个activity的应用程序只声明了android.intent.action.MAIN,没有声明android.intent.category.LAUNCHER,eclipse运行将报错。
0 0
- android中intent-filter的分析和具体使用用例
- Android中关于Intent filter和Intent的一些用法。
- Android的Intent与Intent Filter使用
- android的Intent 和 Intent Filter
- Android Intent-Filter分析
- Android开发中Intent的具体用法
- Android Intent 和 Intent Filter
- 【android】Intent 和 Intent Filter
- Android Intent和Intent filter
- 浅析Android中Intent以及Intent Filter的运用
- Intent-filter的使用
- intent filter的使用
- Android<我所理解的Intent 和Intent-filter>
- Android中 Intent 与 Intent-filter
- Android Intent Filter简单使用
- Android Intent Filter简单使用
- Android Intent Filter简单使用
- Android中的Intent filter使用
- CS0012: 类型“System.Web.Routing.RouteValueDictionary”在未被引用的程序集中定义。必须添加对程序集“System.Web.Routing, Version
- hook Android系统调用的乐趣和好处
- C++中string构造函数的解析
- 大数据开发----Fabric(入门篇)
- 项目实践积累我的工具类——CommonUtils
- android中intent-filter的分析和具体使用用例
- 蓝桥杯 基础练习01 Java实现
- UVA1583 - Digit Generator
- set
- H264分析源码学习之结构体篇——h264_stream_t结构体
- 【算法系列-11】回溯算法-八皇后
- sql联合查并统计子表符合的总数
- HDU 3639 Tarjan + 缩点 + 反建图 + 搜索
- hyper-v查看虚拟机启动顺序