gpt4 book ai didi

java - 使用 Android SIP 堆栈注册 SIP 配置文件

转载 作者:行者123 更新时间:2023-12-01 17:35:23 32 4
gpt4 key购买 nike

我一直在开发一个应用程序,该应用程序能够让用户使用 SIP 调用和接听电话,灵感来自 SIPDemo,其中直到我从手机上卸载该应用程序为止,它都工作正常,它完成了注册,显示了消息“准备好”,然后继续进行调用处理。现在它不会进入 Sipregistrationlistener,并显示错误“尝试关闭管理器 1 SipException 时出错:无法创建 SipSession;网络不可用?”。

据我了解,我怀疑问题是由于之前的 SIP 帐户仍然链接,因此在应用程序中自动打开,不允许任何注册,如本文解决方案“Android Native SIP Stack not registering client”中所述。 ”,但我不知道如何处理这个问题,在 onDestroy、onPause 上引入 closelocalprofile 函数没有效果。此外,直到最近它确实显示了消息“SipManager 已准备好调用”并且它已打开,但现在尽管没有更改代码中的任何内容,但它却没有显示,因此问题可能不一定是这个。

在打印方面,显示以下消息:- 不显示与状态相关的消息;-日志显示“创建管理器”和“构建新配置文件”;

此外,我已经拥有支持 SIP 通信的权限和 list 编码。

我现在知道这个堆栈不是最好的,但我不想放弃这个项目,所以任何帮助或提示将不胜感激。在最后一种情况下,在准备过程中,如果没有找到解决方案/进展,如果你们中的任何人也可以推荐类似的替代堆栈,我们也将不胜感激。

这是代码:

public SipManager sipManager = null;//SIPMANAGER
public SipProfile sipProfile = null;//SIPPROFILE
public SipAudioCall call = null;//SIPAUDIOCALL
public IncomingCallReceiver callReceiver;

@Override
protected void onCreate(Bundle savedInstanceState)
{
Permissions();
Supported();

initManager();

MakeCallButton.setOnClickListener(new View.OnClickListener() /onclick event
{
@Override
public void onClick(View view)
{
initCall();
}
});
EndCallButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view) {
try
{
call.endCall();
}
catch (SipException e)
{
status("Error when trying to end call. " + e);
}
}
});
}

public void initManager()//SIPMANAGER
{
if(sipManager == null)
{
sipManager = SipManager.newInstance(this); //Creates a manager instance. Returns null if SIP API is not supported
Log.d("Manager", "Creating Manager");
}

initLocalProfile();
}
public void initLocalProfile()
{
if (sipManager == null)
{
Log.d("Manager", "There is no manager");
return;
}
if (sipProfile != null)
{
Log.d("Profile", "There is already a profile 1");
closeLocalProfile();
}

//localprofiledata
String user = "x";
String domain = "xxx";
String pass = "zzzz";

try
{
Log.d("Profile", "Building a new profile");
SipProfile.Builder builder = new SipProfile.Builder(user, domain); //user of the SIP account & the SIP server domain
builder.setPassword(pass);//Sets the password of the SIP account
builder.setOutboundProxy(domain);//Sets the outbound proxy of the SIP server
builder.setPort(5060);//port number
builder.setProtocol("UDP");
builder.setAutoRegistration(false);

sipProfile = builder.build();//Builds and returns the SIP profile object.

Intent sipIntent = new Intent();//intent for the calls
sipIntent.setAction("android.Login.INCOMING_CALL");
PendingIntent pi = PendingIntent.getBroadcast(this, 0, sipIntent, Intent.FILL_IN_DATA);
sipManager.open(sipProfile, pi, null);//Opens the profile for making calls and/or receiving generic SIP calls

//Sets the listener to listen to registration events. No effect if the profile has not been opened to receive call

sipManager.setRegistrationListener(sipProfile.getUriString(), new SipRegistrationListener()
{
public void onRegistering(String localProfileUri)
{
//Called when a registration request is sent
status("Registering");
}
public void onRegistrationDone(String localProfileUri, long expiryTime)
{
//Called when the registration succeeded
status("Ready");
}
public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage)
{
//Called when the registration failed
status("Registration Failed " + localProfileUri + errorCode + errorMessage );
}
});
if (sipManager.isRegistered(sipProfile.getUriString()))
{
Log.d("Profile","SipManager is ready for calls");
}
if (sipManager.isOpened(sipProfile.getUriString()))
{
Log.d("Profile","SipManager is open");
}
}
catch (ParseException pe)
{
status("Connection Error");
}
catch (SipException sipe)//if calling the SIP service results in an error
{
status("Error with SIP " + sipe);
}
catch (SecurityException se)
{
status("Error with security" + se);
}
catch (RuntimeException re)
{
status("Error with runtime" + re);
}
catch (Exception e)
{
status("Error" + e);
}
}
public void closeLocalProfile()
{
if (sipManager == null)
{
Log.d("Manager", "There is no manager 1");
return;
}
try
{
if (sipProfile != null)
{
Log.d("Profile", "There is already a profile 2");
sipManager.close(sipProfile.getUriString()); //Closes the specified profile to not make/receive calls
}
}
catch (SipException se)//if calling the SIP service results in an error
{
status("Error while closing SIP" + se);
}
}

public void initCall()
{
callstatus("Adress: " + sipAddress);

try
{
SipAudioCall.Listener listener = new SipAudioCall.Listener() //Listener for events relating to a SIP call, such as when a call is being recieved ("on ringing") or a call is outgoing ("on calling")
{
@Override
public void onCalling(SipAudioCall call)
{
Log.d("initCall", "Initiating session! " + sipAddress);
}
@Override
public void onCallEstablished(SipAudioCall call)
{
Log.d("initCall", "Call started! " + sipAddress);
call.startAudio();//Starts the audio for the established call. This method should be called after onCallEstablished(SipAudioCall) is called
Enter();
}
@Override
public void onRinging(SipAudioCall call, SipProfile caller)
{
Log.d("initCall", "Ringing " + sipAddress);
}
@Override
public void onRingingBack(SipAudioCall call) //Called when a RINGING response is received for the INVITE request sent
{
Log.d("initCall", "Ringing back " + sipAddress);
}
@Override
public void onCallBusy(SipAudioCall call)
{
Log.d("initCall", "Call busy " + sipAddress);
}
@Override
public void onCallEnded(SipAudioCall call)
{
Log.d("initCall", "Call Over ");
call.close();
}
@Override
public void onError(SipAudioCall call, int errorCode, String errorMessage)
{
//super.onError(call, errorCode, errorMessage);
Log.d("initCall", "Error! " + errorMessage + errorCode);
}
};
//the call object that carries out the audio call
call = sipManager.makeAudioCall(sipProfile.getUriString(), sipAddress, listener, 30);
}
catch (Exception e)
{
status("Error when trying to close manager 1. " + e);
if (sipProfile != null)
{
try
{
sipManager.close(sipProfile.getUriString());
}
catch (Exception ee)
{
status("Error when trying to close manager 2. " + ee);
}
}
if (call != null)
{
call.close();
}
}
}

public void status(final String status)//status about the program
{
StatusTextView = (TextView) findViewById(R.id.StatusTextView);
StatusTextView.setText(status);
}

public void callstatus(final String callstatus)//status about the call
{
CallTextView = (TextView) findViewById(R.id.CallTextView);
CallTextView.setText(callstatus);
}

感谢您的时间和关注。

最佳答案

更新

通过重新安装应用程序后重新启动设备以及将代码从 Android Studio 重新发送到手机相结合,成功解决了以前的这些错误。正如我上面所说,我对错误来源的怀疑是由于该堆栈存在错误,但它现在可以工作,并且我对成品感到满意。

尽管这里没有得到任何回复,但我希望这个帖子可以对某人有所帮助。

感谢您的时间和关注。

关于java - 使用 Android SIP 堆栈注册 SIP 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61050953/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com