I'm trying to establish a call using sip on Android. The permissions in my manifest are:
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.USE_SIP"/>
<uses-permission android:name="android.permission.INTERNET"/>
The CALL_PHONE permission is there because my app also calls regular numbers.
This is the activity code:
package x.x.x;
import java.text.ParseException;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.net.sip.SipAudioCall;
import android.net.sip.SipException;
import android.net.sip.SipManager;
import android.net.sip.SipProfile;
import android.os.Bundle;
import android.util.Log;
public class CallScreen extends Activity{
public SipManager manager = null;
public SipProfile me = null;
public SipAudioCall call = null;
//IncomingCallReceiver callReceiver;
String domain = "myserver.net";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.callscreen);
initManager();
Log.d("Z:","Done initManger()");
Thread waiter = new Thread(){
@Override
public void run() {
// TODO Auto-generated method stub
try {
sleep(10000);
Log.d("Z:","Done waiting");
initCall();
Log.d("Z:","Done initCall");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
waiter.start();
//initCall();
}
public void initManager()
{
manager = SipManager.newInstance(this);
initLocalProfile();
}
public void initLocalProfile()
{
String username = "user";
String password = "12345";
String domain = "myserver.net";
try {
SipProfile.Builder builder = new SipProfile.Builder(username,domain);
builder.setPassword(password);
me = builder.build();
//Intent intent = new Intent();
//PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA);
//manager.open(me,pi,null);
manager.open(me);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void initCall()
{
SipAudioCall.Listener listener = new SipAudioCall.Listener(){
@Override
public void onCallEstablished(SipAudioCall call) {
// TODO Auto-generated method stub
//super.onCallEstablished(call);
call.startAudio();
call.setSpeakerMode(true);
call.toggleMute();
}
@Override
public void onCallEnded(SipAudioCall call) {
// TODO Auto-generated method stub
super.onCallEnded(call);
}
};
try {
call = manager.makeAudioCall(me.getUriString(), "12345678910", listener, 30);
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
The error shown on logcat:
01-26 22:20:25.710: D/SipAudioCall(31060): sip session error: CLIENT_ERROR: libcore.io.ErrnoException: getaddrinfo failed: ENOENT (No such file or directory)
I'm trying to make this tiny example work before i organize this code a little differently (username and pass not hard-coded, for example). I'm also not very familier with sip. Really appriciate any advice.
any ideas? Thanks!
The problem is on the following line:
call = manager.makeAudioCall(me.getUriString(), "12345678910", listener, 30);
The second parameter of makeAudioCall
method must be the URI of the SIP profile to make the call to
, but you provided only its username (i.e: "12345678910"). Change it to something like:
call = manager.makeAudioCall(me.getUriString(), "sip:[email protected]", listener, 30);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With