设为首页收藏本站

移动叔叔

搜索
查看: 755|回复: 0
打印 上一主题 下一主题

[其它] Android开发Intent filter的学习

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-29 15:02:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Android开发当中我们知道,每个组件可以有一个或者多个intent filter。提到Intent filter我们就来了解下Intent filter,Intent filter有三个部分构成,分别是action,data和category。Intent filter是在Android的主配置文件AndroidManifest.xml中注册,主要用来指明Activity, Service, Broadcast reciver这三个组件可以响应哪些隐式intents。
  下面通过代码分析每个部分的功能。
  <intent-filter android:label="@string/Asen's blog">
  <action android:name="android.intent.action.MAIN" />
  <action android:name="android.intent.action.VIEW" />
  <action android:name="android.intent.action.EDIT" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.LAUNCHER" />
  <category android:name="android.intent.category.ALTERNATIVE" />
  <data android:mimeType="video/mpeg" android:scheme="http".../>
  <data android:mimeType="audio/mpeg" android:content="com.example.project:200/folder/subfolder/etc"/>
  </intent-filter>
  每个action, category, data都是一行,如果有多个就写多行。"android.intent.action.MAIN" and "android.intent.category.LAUNCHER"这两个是程序入口点的filter必须部分。比如说短信这个应用,当你点击MMS的图标程序启动后,映入使用者的一个界面(所有收到的短信列表),这个短信列表界面就是程序的入口点,通俗的讲就是一个application启动后显示的第一个界面。另外,"android.intent.category.DEFAULT"这个category是用来指明组件是否可以接收到隐式Intents,所以说除了程序入口点这个filter不用包含DEFAULT category外,其余所有intent filter都要有这个category。
  data有两部分构成,一个是数据类型,另一个是URI。每个URI包括四个属性参数(scheme,host, port, path),形如:scheme://host:port/path
  Intent filter和Intent相互配合,实现了Android系统四大组件之间的信使功能。
  举个例子 content://com.examplproject:e.200/folder/subfolder/etc 这个列子中scheme是content,host是com.examplproject,port是200,path是folder/subfolder/etc
您需要登录后才可以回帖 登录 | 注册

关闭

站长推荐上一条 /1 下一条

© 2008-2024 移动叔叔. 版权所有,专业的网络售后平台 ( 闽ICP备18006692号-3 )

商务合作点击这里给我发消息|Email:service@mobileuncle.com|手机版|Archiver|移动叔叔     

GMT+8, 2024-4-26 15:11 , Processed in 0.069566 second(s), 12 queries , Gzip On, Memcache On.

返回顶部