Intent filter的学习(关于主界面的设置)

Intent filter是在Android的主配置文件AndroidManifest.xml中注册,主要用来指明Activity, Service, Broadcast reciver这三个组件可以响应哪些隐式intents。每个组件可以有一个或者多个intent filter。

  Intent filter有三个部分构成,分别是action,data和category。下面通过代码分析每个部分的功能。

  <intent-filter android:label="@string/Asen's blog">

  <action android:name="android.intent.action.MAIN" />//拥有此项条件设定的activity便为应用执行的主界面


  <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举个例子 content://com.examplproject:e.200/folder/subfolder/etc 这个列子中scheme是content,host是com.examplproject,port是200,path是folder/subfolder/etcIntent filter和Intent相互配合,实现了Android系统四大组件之间的信使功能。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值