我刚开始一个新项目,作为概念证明,我只想用sip进行简单的音频通话。在应用程序中,我输入一个电话号码,然后单击一个按钮即可开始通话。我正在两个Android设备之间测试这个。在设备A上,我安装了应用程序并单击了呼叫按钮。设备B开始响铃,所以我知道我有连接。我的问题是两边都没有音频。设备A上甚至没有拨号音。
这是我的清单
<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();
}
}
}
答案 0 :(得分:1)
我现在尝试使用SIP库,并且是Android开发中的新手。
首先,我在我的项目中关注demo code。 只需将所有文件拖到项目中并修改包的一些名称空间
即可我的Manifests权限和功能如下所示:
<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" />
活动&amp;接收器你可以参考链接中的清单文件。
30分钟前我没有声音的原因是我在android:name
留下逗号... OMG
顺便说一句,我使用一个稳定的VoIP软件来调用我的应用程序,这是测试代码中是否有任何问题的好方法。
祝你好运〜我也是Android开发中的新手,为期两周。答案 1 :(得分:0)
感谢您的回复。后来我发现我在清单中缺少一两个权限。这是我现在在清单中设置的完整权限。现在一切正常。
<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.CALL_PHONE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CONFIGURE_SIP" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<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" />
<uses-feature
android:name="android.hardware.telephony"
android:required="true" />
为了模拟拨号音,我必须在onRingBack重载中使用medial播放器。
@Override
public void onRingingBack(final SipAudioCall call) {
Log.i("SWARM", "Ringing...");
try {
Resources res = getResources();
AssetFileDescriptor afd = res.openRawResourceFd(R.raw.ringing);
mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
mp.setLooping(true);
try {
mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
mp.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mp.start();
} catch (IllegalArgumentException e1) {
e1.printStackTrace();
} catch (SecurityException e1) {
e1.printStackTrace();
} catch (IllegalStateException e1) {
e1.printStackTrace();
}
setButtonToRed();
}