Intent 匹配规则
?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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 团队项目第二阶段冲刺站立会议04
- 下一篇: 如何架设灵活多变的数据采集路线?