简体   繁体   English

Android SIP API - 如何接听已接来电

[英]Android SIP API - How to pickup received call

When using the SIP API, how can I answer a call I'm receiving. 使用SIP API时,如何接听我正在接收的电话。 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. 我使用sipdemo中的incomingcallreceiver类进行测试,我在WalkieTalkieActivity类中添加了一个拾取按钮,当呼叫进入时我应该启用但我无法弄清楚如何接听入站呼叫。 Any help or examples would be appreciated. 任何帮助或示例将不胜感激。

To be more specific, here is the sample code from IncomingCallReceiver class: 更具体地说,这是来自IncomingCallReceiver类的示例代码:

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 WalkieTalkieActivity类使用以下方法接收呼叫:在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 : 根据开发人员SIP 指南

When the SIP service receives a new call, it sends out an intent with the action string provided by the application. 当SIP服务收到新呼叫时,它会发出一个具有应用程序提供的动作字符串的意图。 In SipDemo, this action string is android.SipDemo.INCOMING_CALL. 在SipDemo中,此操作字符串是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. 此代码摘录自SipDemo,显示了如何使用基于操作字符串android.SipDemo.INCOMING_CALL的待定意图创建SipProfile对象。 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). 当SipProfile接收到一个呼叫时,PendingIntent对象将执行广播:(这指的是创建配置文件的上面的代码)然后指南继续说:广告将被意图过滤器截获,然后将触发广播接收器(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: 您可以在应用程序的清单文件中指定intent过滤器,或者在代码中执行,如在应用程序的Activity的SipDemo示例应用程序的onCreate()方法中:

Im looking to add a pickup button to the WalkieTalkieActivity class that is enabled onRinging and will answer an incoming call when clicked. 我希望将一个拾取按钮添加到在铃声上启用的WalkieTalkieActivity类,并在点击时接听来电。

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: 然后在walkietalkieactivity Class中设置一个新的SipAudioCall,并在其中使用onclicklistener进行onRinging的监听,然后进行正常的调用处理,如:

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

--Thanks Daniel - 谢谢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. 我必须在我的主ui类中从我的按钮调用来电活动中的方法。 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. 引用IncomingCallReceiver.incomingCall.answercall会将状态更改为应答但不会失败并且实际上没有回答,即使未建立呼叫,startaudio也会发送RTP。 I tried moving this inside a listener for oncallestablished but it wasnt happening so it did not matter. 我尝试将其移动到监听器中以进行oncallestablished,但它没有发生,所以它没关系。 Im still very new at this so I apologize if my terminology is off. 我仍然很新,所以如果我的术语关闭,我道歉。

Thanks, Daniel 谢谢,丹尼尔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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