Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發實例 >> Android開發Intent filter的學習

Android開發Intent filter的學習

編輯:Android開發實例

  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. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved