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