需求: 过滤指定action的intent
场景:一个广播接收器需要接收一个广播,起初只用actiion来标示,但是后期发现
我如果正在跟好友A聊天的情况下,我只想监听来自A以外的广播
解决办法:IntentFilter通过设置data相关属性来实现
先看一下官方文档
-
Data test
-
Like the action and categories, the data specification for an intent filter is contained in a subelement. And, as in those cases, the subelement can appear multiple times, or not at all. For example:
<intent-filter . . . > <data android:mimeType="video/mpeg" android:scheme="http" . . . /> <data android:mimeType="audio/mpeg" android:scheme="http" . . . /> . . .</intent-