问题描述
这是可能的,以检查是否广播发送的固定模式?
Is this possible to check if a broadcast was sent in sticky mode?
我们能完全中止/删除持久广播?如果是的话,那么能不能为正常进行,并下令节目?
Can we completely abort/remove a sticky broadcast? If yes, then can it be done for both normal and ordered broadcasts?
推荐答案
在的onReceive()
您可以使用下面的调用:
In onReceive()
you can use the following calls:
isInitialStickyBroadcast()
- 这会告诉你,如果你正在处理被发送的粘性,是当前的广播时 BroadcastReceiver的
注册。
isInitialStickyBroadcast()
- This will tell you if the broadcast you are currently processing was sent as "sticky" and was the current one when the BroadcastReceiver
was registered.
isOrderedBroadcast()
- 这会告诉你,如果你正在处理被送到作为广播一个有序的广播
isOrderedBroadcast()
- This will tell you if the broadcast you are currently processing was sent as an "ordered" broadcast.
如果你只是想看看是否有粘性的广播,你可以叫
If you just want to see if there is a "sticky" broadcast, you can call
registerReceiver (BroadcastReceiver receiver, IntentFilter filter)
和供应空
为接收
参数。这将返回所有粘性广播没有实际注册的接收器。
and supply null
as the receiver
parameter. This will return any "sticky" broadcast without actually registering the receiver.
您可以使用删除持久广播消息:
You can remove a sticky broadcast using:
removeStickyBroadcast(Intent intent)
但是,恕我直言,这将是适得其反。通常粘性广播发送到指示的当前状态的东西。因此删除这将意味着,这是不可能的应用程序,以确定当前状态。
However, IMHO that would be counter-productive. Usually "sticky" broadcasts are sent to indicate the current state of something. So removing it would imply that it isn't possible for an application to determine the current state.
这篇关于这是可能的,以检查是否广播发送的固定模式?它可以被中止/删除吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!