乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Android Intent和Intent Filter詳解(四)

       wanwanstudy 2012-02-11
      Using intent matching 使用intent匹配

              intent和intent filter相匹配, 不僅為了尋找并啟動(dòng)一個(gè)目標(biāo)組件, 也是為了尋找設(shè)備上組件的信息. 例如, android系統(tǒng)啟動(dòng)了應(yīng)用程序啟動(dòng)器, 該程序位于屏幕的頂層, 顯示了用戶可以啟動(dòng)的程序, 這是通過查找設(shè)備上所有的action為"android.intent.action.MAIN" ,category為"android.intent.category.LAUNCHER"的intent filter所在的activity實(shí)現(xiàn)的. 然后它顯示了這些activity的圖標(biāo)和標(biāo)題. 類似的, 它通過尋找 "android.intent.category.HOME"的filter來定位主屏幕程序.

             應(yīng)用程序可以用相同的方式來使用intent匹配. PackageManager 有一組query...()方法來尋找接受某個(gè)特定intent的所有組件, 還有一系列resolve...()方法來決定響應(yīng)一個(gè)intent的最佳組件. 例如, queryIntentActivities()返回一個(gè)activity列表, 這些activity可以執(zhí)行傳入的intent. 類似的還有queryIntentServices()和queryIntentBroadcastReceivers().

              Note Pad Example 例子:記事本

              記事本示例程序讓用戶可以瀏覽一個(gè)筆記列表, 查看, 編輯, 刪除和增加筆記. 這一節(jié)關(guān)注該程序定義的intent filter.

              在其manifest文件中, 記事本程序定義了三個(gè)activity, 每個(gè)有至少一個(gè)intent filter. 它還定義了一個(gè)content provider來管理筆記數(shù)據(jù). manifest 文件如下:

      java代碼:
      1. <manifest xmlns:android="http://schemas./apk/res/android"
      2. package="eoe.demo">
      3. <application android:icon="@drawable/app_notes"
      4. android:label="@string/app_name" >

      5. <provider android:name="NotePadProvider"
      6. android:authorities="com.google.provider.NotePad" />

      7. <activity android:name="NotesList" android:label="@string/title_notes_list">
      8. <intent-filter>
      9. <action android:name="android.intent.action.MAIN" />
      10. <category android:name="android.intent.category.LAUNCHER" />
      11. </intent-filter>
      12. <intent-filter>
      13. <action android:name="android.intent.action.VIEW" />
      14. <action android:name="android.intent.action.EDIT" />
      15. <action android:name="android.intent.action.PICK" />
      16. <category android:name="android.intent.category.DEFAULT" />
      17. <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
      18. </intent-filter>
      19. <intent-filter>
      20. <action android:name="android.intent.action.GET_CONTENT" />
      21. <category android:name="android.intent.category.DEFAULT" />
      22. <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
      23. </intent-filter>
      24. </activity>

      25. <activity android:name="NoteEditor"
      26. android:theme="@android:style/Theme.Light"
      27. android:label="@string/title_note" >
      28. <intent-filter android:label="@string/resolve_edit">
      29. <action android:name="android.intent.action.VIEW" />
      30. <action android:name="android.intent.action.EDIT" />
      31. <action android:name="com.android.notepad.action.EDIT_NOTE" />
      32. <category android:name="android.intent.category.DEFAULT" />
      33. <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
      34. </intent-filter>
      35. <intent-filter>
      36. <action android:name="android.intent.action.INSERT" />
      37. <category android:name="android.intent.category.DEFAULT" />
      38. <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
      39. </intent-filter>
      40. </activity>

      41. <activity android:name="TitleEditor"
      42. android:label="@string/title_edit_title"
      43. android:theme="@android:style/Theme.Dialog">
      44. <intent-filter android:label="@string/resolve_title">
      45. <action android:name="com.android.notepad.action.EDIT_TITLE" />
      46. <category android:name="android.intent.category.DEFAULT" />
      47. <category android:name="android.intent.category.ALTERNATIVE" />
      48. <category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
      49. <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
      50. </intent-filter>
      51. </activity>
      52. </application>
      53. </manifest>
      復(fù)制代碼

             第一個(gè)activity, NoteList, 和其它activity不同, 因?yàn)樗僮饕粋€(gè)筆記的目錄(筆記列表), 而不是一個(gè)單獨(dú)的筆記. 它一般作為該程序的初始界面. 它可以做以下三件事:

      java代碼:
      1. <intent-filter>
      2. <action android:name="android.intent.action.MAIN" />
      3. <category android:name="android.intent.category.LAUNCHER" />
      4. </intent-filter>
      復(fù)制代碼

              該filter聲明了記事本應(yīng)用程序的主入口. 標(biāo)準(zhǔn)的MAIN action是一個(gè)不需要任何其它信息(例如數(shù)據(jù)等)的程序入口, LAUNCHER category表示該入口應(yīng)該在應(yīng)用程序啟動(dòng)器中列出.

      java代碼:
      1. <intent-filter>
      2. <action android:name="android.intent.action.VIEW" />
      3. <action android:name="android.intent.action.EDIT" />
      4. <action android:name="android.intent.action.PICK" />
      5. <category android:name="android.intent.category.DEFAULT" />
      6. <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
      7. </intent-filter>

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多