Android SIP API - How to pickup received call
<p>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. </p>

<p>To be more specific, here is the sample code from IncomingCallReceiver class:</p>

<pre><code>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();
}}}}
</code></pre>

<p>The WalkieTalkieActivity class uses the following for receiving a call:
within onCreate</p>

<pre><code>IntentFilter filter = new IntentFilter();
filter.addAction("android.SipDemo.INCOMING_CALL");
callReceiver = new IncomingCallReceiver();
this.registerReceiver(callReceiver, filter);
</code></pre>

<p>and where the profile is created</p>

<pre><code>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);
</code></pre>

<p>According to the developer SIP <a href="http://developer.android.com/guide/topics/network/sip.html" rel="nofollow">guide</a>:</p>

<p>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. </p>

<p>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:</p>

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

<p>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.</p>

<p>Edit - Could this work?:</p>

<pre><code>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();
}}}}
</code></pre>

<p>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:</p>

<pre><code>inbound.answerCall(30);
inbound.startAudio();
inbound.setSpeakerMode(true);
if(inbound.isMuted()) {
inbound.toggleMute();
}
</code></pre>

<p>--Thanks
Daniel</p>
