我想知道是否可以注册广播接收器以接收两个意图?
我的代码如下:
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));
每次发送时我都会获得注册意图,但是当我发送它时,我从未获得UNREGISTERED Intent。
我应该为UNREGISTERED Intent设置另一个广播接收器吗?
答案 0 :(得分:25)
请勿创建IntentFilter
内联,然后使用addAction
方法添加UNREGISTERED
操作,即:
IntentFilter filter = new IntentFilter(SIPEngine.SIP_REGISTERED_INTENT);
filter.addAction(SIPEngine.SIP_UNREGISTERED_INTENT);
context.registerReceiver(sipRegistrationListener, filter);