android对一个ordered broadcast进行拦载的方法

来源:互联网 发布:淘宝联盟多少号提现 编辑:程序博客网 时间:2024/06/05 05:42
所谓ordered broadcast就是指那些调用 Context.sendOrderedBroadcast去发送的广播。
这种广播是按照接收者的filter顺序执行的,
这个顺序:
1、如果没有特权者,就是先来后到。
2、如果有特权者,特权者号大的靠前。
设置特权号,如下:


<intent-filter android:icon="drawable resource"
               
android:label="string resource"
               
android:priority="integer" >
    . . .
</intent-filter>
也可以在代码中设置,

IntentFilter

public final void setPriority (int priority)

这个值的范围是-1000到1000,默认是0
所以,设了这个你的broadcast receiver就能早点接到broadcast。
接到以后,
你就可以调

BroadcastReceiver

abortBroadcast ()

来中止这个广播继续传播下去,这样,你的拦载的目的就达到了。

注意:

This method does not work with non-ordered broadcasts such as those sent with Context.sendBroadcast

也就是说如果不是ordered的broadcast,还是会一直传下去。

原创粉丝点击