接收SIP呼叫时在BroadcastReceiver上启动活动

时间:2014-03-25 13:07:27

标签: android broadcastreceiver sip

我有我的IncomingCallReceiver类,我希望将其来电发送到另一个活动,以便为用户提供接收或拒绝来电的选项这是我的IncomingReceiver类,并且显然没有想法所以如果有人可能建议我如何做

public class IncomingCallReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {     

    SipAudioCall incomingCall = null;
    try {

        SipAudioCall.Listener listener = new SipAudioCall.Listener() {
            @Override
            public void onRinging(SipAudioCall call, SipProfile caller) {
                try {
                    call.answerCall(30);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };

        MainActivity wtActivity = (MainActivity) context;                       

        incomingCall = wtActivity.manager.takeAudioCall(intent, listener);
        incomingCall.answerCall(30);
        incomingCall.startAudio();
        incomingCall.setSpeakerMode(true);

        wtActivity.call = incomingCall;

        wtActivity.updateStatus(incomingCall);

    } catch (Exception e) {
        if (incomingCall != null) {
            incomingCall.close();
        }
    }
}
}

1 个答案:

答案 0 :(得分:1)

嗨,问题已在stackoverflow中得到解答,无论如何都要改变你的onRinging方法如下。

SipAudioCall incomingCall = null;
try {

    SipAudioCall.Listener listener = new SipAudioCall.Listener() {
        @Override
        public void onRinging(SipAudioCall call, SipProfile caller) {

          super.onRinging(call, caller);
        }
    };

    MainActivity wtActivity = (MainActivity) context;                       

    incomingCall = wtActivity.manager.takeAudioCall(intent, listener);
    //Method call which handles incoming call.
    showIncomingCall(intent, context);
    wtActivity.call = incomingCall;

    wtActivity.updateStatus(incomingCall);

} catch (Exception e) {
    if (incomingCall != null) {
        incomingCall.close();
    }
}

private void showIncomingCall(Intent intent, Context context) {

    Intent incomingCall = new Intent(context, IncomingCallActivity.class);
    context.startActivity(incomingCall);
}

public static void answerIncomingCall() {

    try {
        incomingCall.answerCall(30);
        incomingCall.startAudio();

        if (incomingCall.isMuted()) {
            incomingCall.toggleMute();

        }
    }

    catch (Exception e) {

        System.out.println(e.toString());
    }

}

public static void rejectIncomingCall() {

    try {
        if (incomingCall != null) {

            incomingCall.endCall();
            incomingCall.close();
        }

    } catch (Exception e) {

        System.out.println(e.toString());
    }
}

}

在您的来电活动中,您有接听和拒绝来电按钮,请输入以下代码。

btnAnswer.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            IncomingCallReceiver.answerIncomingCall();

        }
    });

    btnDecline.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {


            IncomingCallReceiver.rejectIncomingCall();
            finish();
        }
    });