我刚刚开始一个新项目,作为概念证明,我只想使用sip进行简单的音频通话。在应用程序中,我输入一个电话号码,然后单击一个按钮以开始通话。我正在两个Android设备之间进行测试。在设备A上,我安装了该应用程序,然后单击“ call ”按钮。设备B开始响铃,所以我知道我已经建立了连接。我的问题是两侧都没有音频。设备A上甚至没有拨号音。
这是我的 list
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CONFIGURE_SIP" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-feature android:name="android.software.sip" android:required="true" />
<uses-feature android:name="android.hardware.wifi" android:required="true" />
<uses-feature android:name="android.hardware.sip.voip" android:required="true" />
<uses-feature android:name="android.hardware.microphone" android:required="true" />
这是我的Java代码
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_make_call);
//getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
initializeManager();
}
public void initializeManager()
{
if(manager == null)
{
manager = SipManager.newInstance(this);
}
initializeLocalProfile();
}
public void initializeLocalProfile()
{
if (manager == null)
{
return;
}
if (me != null)
{
closeLocalProfile();
}
String username = "username"; // I do have the correct credentials
String domain = "proxy";
String password = "password";
try {
SipProfile.Builder builder = new SipProfile.Builder(username, domain);
builder.setPassword(password);
me = builder.build();
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);
// This listener must be added AFTER manager.open is called,
// Otherwise the methods aren't guaranteed to fire.
manager.setRegistrationListener(me.getUriString(), new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
Log.d("call","Registering with SIP Server...");
}
public void onRegistrationDone(String localProfileUri, long expiryTime) {
Log.d("call","Ready");
}
public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) {
Log.d("call","Registration failed. Please check settings.");
}
});
} catch (ParseException pe) {
Log.d("err","Connection Error.");
} catch (SipException se) {
Log.d("err","Connection error.");
}
}
public void closeLocalProfile()
{
if (manager == null)
{
return;
}
try
{
if (me != null)
{
manager.close(me.getUriString());
}
}
catch (Exception ee)
{
Log.d("onDestroy", "Failed to close local profile.", ee);
}
}
public void onCallButtonTap(View v)
{
phoneText = findViewById(R.id.et_phoneNumber);
ClientPhoneNumber = phoneText.getText().toString();
displayMessage("Call starting...");
try
{
SipAudioCall.Listener listener = new SipAudioCall.Listener()
{
@Override
public void onCallEstablished(SipAudioCall call)
{
Log.d("log", "Call started!");
call.setSpeakerMode(true);
call.startAudio();
}
@Override
public void onCallEnded(SipAudioCall call)
{
displayMessage("Call Ended");
closeLocalProfile();
}
};
manager.makeAudioCall(me.getUriString(), ClientPhoneNumber + "@proxy.cloudpbx.voiportal.net:5060", listener, 30);
}
catch (Exception e)
{
if (me != null)
{
try
{
manager.close(me.getUriString());
}
catch (SipException e1)
{
e1.printStackTrace();
}
}
if (call != null)
{
call.close();
}
}
}
最佳答案
这些天,我正在尝试使用SIP库,并在android开发中使用新手。
首先,在我的项目中遵循demo code。
只需将所有文件拖到您的项目并修改包的某些 namespace
我的 list 权限和功能如下所示:
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-feature android:name="android.software.sip" android:required="true" />
<uses-feature android:name="android.hardware.sip.voip" android:required="true" />
<uses-feature android:name="android.hardware.wifi" android:required="true" />
<uses-feature android:name="android.hardware.microphone" android:required="true" />
Activity 和接收者,您可以引用链接上的 list 文件。30分钟前我没有声音的原因是我在
android:name
中留下了逗号... OMG顺便说一句,我使用一种稳定的VoIP软件来调用我的应用程序,这是测试代码中是否存在任何问题的好方法。
祝您好运!我也是Android开发 Realm 的新手,已有2周了。
关于android - Android SIP根本没有音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49811342/