日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Intent 匹配规则

發布時間:2025/3/21 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Intent 匹配规则 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?1.在AndroidManifest.xml中可以為 每個 Activity,Service 設置多個Intent-Filter;

?

?在系統啟動和程序安裝之后,android會收集AndroidManifest.xml 中配置的 Intent-Filter.

? ?每個intent-filter 從action category data三個量來過濾 intent.

  • Intent-Filter和Intent的設置規則

? 1.每個intent-filter對象(這里是intent-filter不是 AndroidManifest.xml中的intent-filter的子節點,Activity 節點可以沒有intent-filter子節點 可以配置 0-n個action, 1-n 個category , 0-n個data。IntentFilter 上的 data 節點上可以設置 scheme、host、port、path、mimetype?

? 2.每個intent 可以設置?0-1個 action、0-n 個 category、0-1 個 data。Intent 上可以使用 Uri 設置 data,使用字符串設置 mimetype

? 3. ?在安裝app的時候,intent-filter節點如果沒有配置category,系統不會設置某個默認的category.

   如果在隱式啟動activity的時候,startactivity(intent),系統會自動為這個intent在多匹配一次"android.intent.category.DEFAULT",所以如果要能夠隱式啟動activity,

  必須在AndroidManifest.xml中為activity配置"android.intent.category.DEFAULT",否則無論如何都不會匹配通過的。

?

?

  • Intent-Filter和Intent的匹配規則

?  匹配步驟1,action 2, data ?3,category

  action和category匹配規則:

        intent中的action必須在 intent-filter中設置了的

        intent中的每一個category必須在intent-filter中設置了的。

? ? ?data匹配規則

? ? ? ? ? ? ? ?data格式:<scheme>://<host>:<port>/<path>?

? ? ? ? ? ? ? ? 從前往后匹配,intent中的data只需要和intent-filter中設置的部分匹配就可以了。

     比如 ?intent-filter中設置?<data android:scheme="test" android:host="www.google.com"/>

? ? ? ? ? ? ? 那么

        Uri.parse("test://www.google.com:80"),

        Uri data = Uri.parse("test://www.google.com:88"),?

? ? ? ? ? ? ? ? ? ? ? Uri data = Uri.parse("test://www.google.com")

? ? ? ? ? ? ? ?這三個都是可以匹配的。

      如果設置了mimeType ,那么intent中也要設置mimeType。

?

?

?

?

??

??

?

轉載于:https://www.cnblogs.com/hi0xcc/p/5571761.html

總結

以上是生活随笔為你收集整理的Intent 匹配规则的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。