注册一个广播接收器两个目的

注册一个广播接收器两个目的

本文介绍了Android的 - 注册一个广播接收器两个目的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能注册一个广播接收器收到两个目的?

I was wondering is it possible to register a broadcast receiver to receive two intents?

我的code是如下:

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意图时,我把它。

I get the REGISTERED Intent everytime I send it but I never get the UNREGISTERED Intent when I send it.

我应该建立另一个广播接收机的UNREGISTERED意图是什么?

Should I set up another Broadcast receiver for the UNREGISTERED Intent?

推荐答案

不要创建的IntentFilter 行内,然后使用<$c$c>addAction方法添加的 UNREGISTERED 的行动,即:

Don't create your IntentFilter inline, then use the addAction method to add the UNREGISTERED action, i.e.:

IntentFilter filter = new IntentFilter(SIPEngine.SIP_REGISTERED_INTENT);
filter.addAction(SIPEngine.SIP_UNREGISTERED_INTENT);
context.registerReceiver(sipRegistrationListener, filter);

这篇关于Android的 - 注册一个广播接收器两个目的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 02:06