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

来源:互联网 发布:淘宝有权删除差评吗 编辑:程序博客网 时间:2024/06/01 10:11

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
原创粉丝点击