简体   繁体   中英

Android SIP API - How to pickup received call

When using the SIP API, how can I answer a call I'm receiving. Im using the incomingcallreceiver class from sipdemo for testing and I added a pickup button in the WalkieTalkieActivity class that should be enabled when a call comes in but I cant figure out how to pickup an inbound call. Any help or examples would be appreciated.

To be more specific, here is the sample code from IncomingCallReceiver class:

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();
}}};
WalkieTalkieActivity wtActivity = (WalkieTalkieActivity) context;
incomingCall = wtActivity.manager.takeAudioCall(intent, listener);
incomingCall.answerCall(30);
incomingCall.startAudio();
incomingCall.setSpeakerMode(true);
if(incomingCall.isMuted()) {
incomingCall.toggleMute();
}
wtActivity.call = incomingCall;
wtActivity.updateStatus(incomingCall);
}
catch (Exception e) {
if (incomingCall != null) {
incomingCall.close();
}}}}

The WalkieTalkieActivity class uses the following for receiving a call: within onCreate

IntentFilter filter = new IntentFilter();
filter.addAction("android.SipDemo.INCOMING_CALL");
callReceiver = new IncomingCallReceiver();
this.registerReceiver(callReceiver, filter);

and where the profile is created

Intent i = new Intent();
i.setAction("android.SipDemo.INCOMING_CALL");
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, Intent.FILL_IN_DATA);
manager.open(me, pi, null);

According to the developer SIP guide :

When the SIP service receives a new call, it sends out an intent with the action string provided by the application. In SipDemo, this action string is android.SipDemo.INCOMING_CALL.

This code excerpt from SipDemo shows how the SipProfile object gets created with a pending intent based on the action string android.SipDemo.INCOMING_CALL. The PendingIntent object will perform a broadcast when the SipProfile receives a call: (This referred to the code above where the profile is created) The guide then goes on to say: The broadcast will be intercepted by the intent filter, which will then fire the receiver (IncomingCallReceiver). You can specify an intent filter in your application's manifest file, or do it in code as in the SipDemo sample application's onCreate() method of the application's Activity:

Im looking to add a pickup button to the WalkieTalkieActivity class that is enabled onRinging and will answer an incoming call when clicked.

I have been successful with handling all other general calling issues such as hold, mute, speaker, making calls, and ending calls but I cannot figure this out.

Edit - Could this work?:

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();
}}};
WalkieTalkieActivity wtActivity = (WalkieTalkieActivity) context;
wtActivity.inbound = incomingCall;
wtActivity.updateStatus(incomingCall);
}
catch (Exception e) {
if (incomingCall != null) {
incomingCall.close();
}}}}

and then set up a new SipAudioCall within the walkietalkieactivity Class and a listener for onRinging with the onclicklistener inside of it followed by normal call handling like:

inbound.answerCall(30);
inbound.startAudio();
inbound.setSpeakerMode(true);
if(inbound.isMuted()) {
inbound.toggleMute();
}

--Thanks Daniel

I was able to get this working after several different attempts. I was unable to handle any call objects outside of the incoming call Activity. I had to call a method within the incoming call activity from my button in my main ui class. Referencing IncomingCallReceiver.incomingCall.answercall would change the state to answering but would not fail and not actually answer and startaudio would send RTP even though the call was not established. I tried moving this inside a listener for oncallestablished but it wasnt happening so it did not matter. Im still very new at this so I apologize if my terminology is off.

Thanks, Daniel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM