[英]Android - Registering a broadcast receiver for two intents?
I was wondering is it possible to register a broadcast receiver to receive two intents? 我想知道是否可以注册一个广播接收器来接收两个意图?
My code is as follows: 我的代码如下:
sipRegistrationListener = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (SIPEngine.SIP_REGISTERED_INTENT.equals(action)){
Log.d("SETTINGS ", "Got REGISTERED action");
}
if (SIPEngine.SIP_UNREGISTERED_INTENT.equals(action)){
Log.d("SETTINGS ", "Got UNREGISTERED action");
}
}
};
context.registerReceiver(sipRegistrationListener, new IntentFilter(SIPEngine.SIP_REGISTERED_INTENT));
context.registerReceiver(sipRegistrationListener, new IntentFilter(SIPEngine.SIP_UNREGISTERED_INTENT));
I get the REGISTERED Intent everytime I send it but I never get the UNREGISTERED Intent when I send it. 我每次发送它时都会获得注册意图,但是当我发送它时,我从未获得UNREGISTERED Intent。
Should I set up another Broadcast receiver for the UNREGISTERED Intent? 我应该为UNREGISTERED Intent设置另一个广播接收器吗?
Don't create your IntentFilter
inline, then use the addAction
method to add the UNREGISTERED
action, ie: 不要内联创建
IntentFilter
,然后使用addAction
方法添加UNREGISTERED
操作,即:
IntentFilter filter = new IntentFilter(SIPEngine.SIP_REGISTERED_INTENT);
filter.addAction(SIPEngine.SIP_UNREGISTERED_INTENT);
context.registerReceiver(sipRegistrationListener, filter);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.