日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Intent 匹配规则

發(fā)布時(shí)間:2025/3/21 编程问答 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Intent 匹配规则 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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

?

?在系統(tǒng)啟動(dòng)和程序安裝之后,android會(huì)收集AndroidManifest.xml 中配置的 Intent-Filter.

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

  • Intent-Filter和Intent的設(shè)置規(guī)則

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

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

? 3. ?在安裝app的時(shí)候,intent-filter節(jié)點(diǎn)如果沒有配置category,系統(tǒng)不會(huì)設(shè)置某個(gè)默認(rèn)的category.

   如果在隱式啟動(dòng)activity的時(shí)候,startactivity(intent),系統(tǒng)會(huì)自動(dòng)為這個(gè)intent在多匹配一次"android.intent.category.DEFAULT",所以如果要能夠隱式啟動(dòng)activity,

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

?

?

  • Intent-Filter和Intent的匹配規(guī)則

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

  action和category匹配規(guī)則:

        intent中的action必須在 intent-filter中設(shè)置了的

        intent中的每一個(gè)category必須在intent-filter中設(shè)置了的。

? ? ?data匹配規(guī)則

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

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

     比如 ?intent-filter中設(shè)置?<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")

? ? ? ? ? ? ? ?這三個(gè)都是可以匹配的。

      如果設(shè)置了mimeType ,那么intent中也要設(shè)置mimeType。

?

?

?

?

??

??

?

轉(zhuǎn)載于:https://www.cnblogs.com/hi0xcc/p/5571761.html

總結(jié)

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。