I'm making a SIP application and I need multiple profiles in it .
But I can only register 1 profile, once I register the second profile the registration will failed and will give me the SipErrorCode: -9 (IN_PROGRESS) .
Is there a way to register 2 Profiles at the same time ? Is it possible ?
This is how I register my SIP:
public SipManager manager = null;
public SipProfile me = null;
///....
if(manager == null) {
manager = SipManager.newInstance(getActivity());
}
///...
try {
SipProfile.Builder builder = new SipProfile.Builder(username, domain);
builder.setPassword(password);
me = builder.build();
Intent intent = new Intent();
intent.setAction("android.SipDemo.INCOMING_CALL");
PendingIntent pendingIntent = PendingIntent.getBroadcast(mainActivity, 0, intent, Intent.FILL_IN_DATA);
manager.open(me, pendingIntent, null);
manager.setRegistrationListener(me.getUriString(), new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
Log.e("onRegisterR", "Registering SIP... " + localProfileUri);
}
public void onRegistrationDone(String localProfileUri, long expiryTime) {
Log.e("onRegisterS", "Registration Successful! " + localProfileUri);
}
public void onRegistrationFailed(String localProfileUri, int errorCode,
String errorMessage) {
Log.e("onRegisterF", errorMessage);
}
});
} catch (ParseException pe) {
Log.e("ParseException", pe.getMessage());
} catch (SipException se) {
Log.e("SipException", se.getMessage());
}
ps. I just implemented this code twice to make 2 Profiles
Related
I have foreground service acting as MQTT client. I'm using MqttAsyncClient mqttClient for this purpose.
I'm using QoS=1 on subscribe to topic:
mqttClient.subscribe("sensors/s1/", 1);
But in case my phone gets offline for some period of time it miss current period messages. Whole code is below.
Im my another application I'm using MqttAndroidClient mqttAndroidClient and in this case QoS=1 brings all missed messages.
mqttAndroidClient.subscribe(topic, 1, null, new IMqttActionListener() {...})
Why subscription with MqttAsyncClient with QoS=1 not retrieves all messages?
Whole code :
public class MqttGndService extends Service {
private String ip="ssl:myserver",port="8887";
private final IBinder mBinder = new LocalBinder();
private Handler mHandler;
private static final String TAG = "mqttservice";
private static boolean hasWifi = false;
private static boolean hasMmobile = false;
private ConnectivityManager mConnMan;
private volatile IMqttAsyncClient mqttClient;
private String uniqueID;
class MQTTBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
IMqttToken token;
boolean hasConnectivity = false;
boolean hasChanged = false;
NetworkInfo infos[] = mConnMan.getAllNetworkInfo();
for (int i = 0; i < infos.length; i++) {
if (infos[i].getTypeName().equalsIgnoreCase("MOBILE")) {
if ((infos[i].isConnected() != hasMmobile)) {
hasChanged = true;
hasMmobile = infos[i].isConnected();
}
Timber.tag(Utils.TIMBER_TAG).v( infos[i].getTypeName() + " is " + infos[i].isConnected());
} else if (infos[i].getTypeName().equalsIgnoreCase("WIFI")) {
if ((infos[i].isConnected() != hasWifi)) {
hasChanged = true;
hasWifi = infos[i].isConnected();
}
Timber.tag(Utils.TIMBER_TAG).v(infos[i].getTypeName() + " is " + infos[i].isConnected());
}
}
hasConnectivity = hasMmobile || hasWifi;
Timber.tag(Utils.TIMBER_TAG).v( "hasConn: " + hasConnectivity + " hasChange: " + hasChanged + " - " + (mqttClient == null || !mqttClient.isConnected()));
if (hasConnectivity && hasChanged && (mqttClient == null || !mqttClient.isConnected())) {
Timber.tag(Utils.TIMBER_TAG).v("Ready to connect");
doConnect();
Timber.tag(Utils.TIMBER_TAG).v("do connect done");
} else
{
Timber.tag(Utils.TIMBER_TAG).v("Connection not possible");
}
}
}
public class LocalBinder extends Binder {
public MqttGndService getService() {
// Return this instance of LocalService so clients can call public methods
return MqttGndService.this;
}
}
#Override
public IBinder onBind(Intent intent) {
return mBinder;
}
public void publish(String topic, MqttMessage message) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);// we create a 'shared" memory where we will share our preferences for the limits and the values that we get from onsensorchanged
try {
mqttClient.publish(topic, message);
} catch (MqttException e) {
e.printStackTrace();
}
}
#Override
public void onCreate() {
Timber.tag(Utils.TIMBER_TAG).v("Creating MQTT service");
mHandler = new Handler();//for toasts
IntentFilter intentf = new IntentFilter();
setClientID();
intentf.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(new MQTTBroadcastReceiver(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
mConnMan = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
Timber.tag(Utils.TIMBER_TAG).v( "onConfigurationChanged()");
android.os.Debug.waitForDebugger();
super.onConfigurationChanged(newConfig);
}
#Override
public void onDestroy() {
super.onDestroy();
Timber.tag(Utils.TIMBER_TAG).v("Service onDestroy");
}
private void setClientID() {
uniqueID = android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
Timber.tag(Utils.TIMBER_TAG).v("uniqueID=" + uniqueID);
}
private void doConnect() {
String broker = ip + ":" + port;
Timber.tag(Utils.TIMBER_TAG).v("mqtt_doConnect()");
IMqttToken token;
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(true);
options.setMaxInflight(100);//handle more messages!!so as not to disconnect
options.setAutomaticReconnect(true);
options.setConnectionTimeout(1000);
options.setKeepAliveInterval(300);
options.setUserName("cc50e3e91bf4");
options.setPassword("b".toCharArray());
try {
options.setSocketFactory(SocketFactoryMQ.getSocketFactory(this,""));
} catch (KeyStoreException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (CertificateException e) {
e.printStackTrace();
} catch (UnrecoverableKeyException e) {
e.printStackTrace();
}
Timber.tag(Utils.TIMBER_TAG).v("set socket factory done");
try {
mqttClient = new MqttAsyncClient(broker, uniqueID, new MemoryPersistence());
token = mqttClient.connect(options);
token.waitForCompletion(3500);
mqttClient.setCallback(new MqttCallback() {
#Override
public void connectionLost(Throwable throwable) {
try {
mqttClient.disconnectForcibly();
mqttClient.connect();
} catch (MqttException e) {
e.printStackTrace();
}
}
#Override
public void messageArrived(String topic, MqttMessage msg) throws Exception {
Timber.tag(Utils.TIMBER_TAG).v("Message arrived from topic " + topic+ " msg: " + msg );
}
#Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
System.out.println("published");
}
});
Timber.tag(Utils.TIMBER_TAG).v("will subscribe");
mqttClient.subscribe("sensors/s1/", 1);
} catch (MqttSecurityException e) {
Timber.tag(Utils.TIMBER_TAG).v("general connect exception");
e.printStackTrace();
} catch (MqttException e) {
switch (e.getReasonCode()) {
case MqttException.REASON_CODE_BROKER_UNAVAILABLE:
mHandler.post(new ToastRunnable("WE ARE OFFLINE BROKER_UNAVAILABLE!", 1500));
break;
case MqttException.REASON_CODE_CLIENT_TIMEOUT:
mHandler.post(new ToastRunnable("WE ARE OFFLINE CLIENT_TIMEOUT!", 1500));
break;
case MqttException.REASON_CODE_CONNECTION_LOST:
mHandler.post(new ToastRunnable("WE ARE OFFLINE CONNECTION_LOST!", 1500));
break;
case MqttException.REASON_CODE_SERVER_CONNECT_ERROR:
Timber.tag(Utils.TIMBER_TAG).v( "c " + e.getMessage());
e.printStackTrace();
break;
case MqttException.REASON_CODE_FAILED_AUTHENTICATION:
Intent i = new Intent("RAISEALLARM");
i.putExtra("ALLARM", e);
Timber.tag(Utils.TIMBER_TAG).v("b " + e.getMessage());
break;
default:
Timber.tag(Utils.TIMBER_TAG).v( "a " + e.getMessage() +" "+ e.toString());
}
}
mHandler.post(new ToastRunnable("WE ARE ONLINE!", 500));
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Timber.tag(Utils.TIMBER_TAG).v("onStartCommand");
String input = intent.getStringExtra(INTENT_ID);
Timber.tag(Utils.TIMBER_TAG).v("onStartCommand "+ input);
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,
0, notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Example Service")
.setContentText(input)
.setSmallIcon(R.drawable.ic_android)
.setContentIntent(pendingIntent)
.build();
startForeground(1, notification);
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyApp::MyWakelockTag");
wakeLock.acquire();
return START_STICKY;
}
}
You are setting cleansession to true (options.setCleanSession(true)); from the docs for setCleanSession:
If set to true the client and server will not maintain state across restarts of the client, the server or the connection. This means
Message delivery to the specified QOS cannot be maintained if the client, server or connection are restarted
The server will treat a subscription as non-durable
I think that the mqtt specs state this more clearly:
If CleanSession is set to 1, the Client and Server MUST discard any previous Session and start a new one. This Session lasts as long as the Network Connection. State data associated with this Session MUST NOT be reused in any subsequent Session
So when your application looses the connection the session is discarded and new messages will not be queued up for delivery. In addition unless you resubscribe when the connection comes back up you will not receive any additional messages.
However be aware that if you set cleansession to false then any new messages received while your client is offline will be queued for delivery (subject to the configuration of the broker) and this might not be what you want to happen if the client could be offline for a long time.
I'm following Google's guidelines to create in app SIP calls as in https://developer.android.com/guide/topics/connectivity/sip.html
I created a test account on sip.zadarma.com which works with a SIP client I downloaded from the Google Play however when I try to register it in my app I get:
onRegistrationFailed errorCode = -4 errorMessage: registration not running
onRegistrationFailed errorCode = -9 errorMessage: 0
#Override
protected void onResume() {
super.onResume();
if (mNumberKeyedIn == null)
mNumberKeyedIn = "";
if (hasSIPPermissions()) {
initializeSIP();
} else {
requestSIPPermission();
}
}
#Override
public void onPause() {
super.onPause();
closeLocalProfile();
}
public void closeLocalProfile() {
if (mSipManager == null) {
return;
}
try {
if (mSipProfile != null) {
mSipManager.close(mSipProfile.getUriString());
if (mSipManager.isRegistered(mSipProfile.getProfileName()))
mSipManager.unregister(mSipProfile, null);
}
} catch (Exception e) {
Log.d(TAG, "Failed to close local profile.", e);
}
}
private void initializeSIP() {
if (callReceiver == null) {
IntentFilter filter = new IntentFilter();
filter.addAction("com.xxxx.android.apps.xxxx.activity.INCOMING_CALL");
callReceiver = new IncomingCallReceiver();
this.registerReceiver(callReceiver, filter);
}
try {
if (mSipManager == null) {
mSipManager = SipManager.newInstance(this);
if (!SipManager.isVoipSupported(this)) {
Toast.makeText(this, getString(R.string.sip_not_supported), Toast.LENGTH_SHORT).show();
return;
}
if (SipManager.isSipWifiOnly(this)) {
Toast.makeText(this, getString(R.string.sip_wifi_only), Toast.LENGTH_SHORT).show();
}
}
if (mSipProfile != null) {
closeLocalProfile();
}
SipProfile.Builder builder = new SipProfile.Builder(BuildConfig.SIP_USERNAME, BuildConfig.SIP_DOMAIN);
builder.setPassword(BuildConfig.SIP_PASSWORD);
//builder.setProtocol("TCP");
//builder.setAuthUserName(BuildConfig.SIP_USERNAME);
//builder.setPort(5060);
//builder.setOutboundProxy(BuildConfig.SIP_OUTBOUND_PROXY);
builder.setAutoRegistration(true);
mSipProfile = builder.build();
Intent intent = new Intent();
intent.setAction("com.xxxx.android.apps.xxxx.activity.INCOMING_CALL");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA);
mSipManager.open(mSipProfile, pendingIntent, null);
mSipManager.setRegistrationListener(mSipProfile.getUriString(), new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
updateStatus(getString(R.string.sip_registering), R.drawable.circle_orange, false);
Log.d(TAG, "onRegistering " + localProfileUri);
}
public void onRegistrationDone(String localProfileUri, long expiryTime) {
updateStatus(getString(R.string.sip_ready), R.drawable.circle_green, true);
Log.d(TAG, "onRegistrationDone " + localProfileUri + " expiryTime = " + expiryTime);
}
public void onRegistrationFailed(String localProfileUri, int errorCode,
String errorMessage) {
updateStatus(getString(R.string.sip_registration_failed), R.drawable.circle_red, false);
Log.e(TAG, "onRegistrationFailed " + localProfileUri + " errorCode = " + errorCode + " errorMessage: " + errorMessage);
}
});
} catch (ParseException e) {
e.printStackTrace();
Toast.makeText(this, getString(R.string.sip_not_configured), Toast.LENGTH_SHORT).show();
} catch (SipException e) {
e.printStackTrace();
Toast.makeText(this, getString(R.string.oops_something_went_wrong_short), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(this, getString(R.string.sip_not_supported), Toast.LENGTH_SHORT).show();
}
}
Any help will be much appreciated.
Following solutions should be tried before to test your Registration server before even looking into code for SipClient.
Try runnig any VoIP SoftPhone client to check your server, if its not working then debug that first i.e. PortNo/IP address issue.
If step one is working then try running Wireshark on server to track reply from incoming REGISTRATION Request from client.
Although from "Error logs " from your text means i.e. IP address is pingable but Registration Port No is not opened.
I don't think this is code issue. It must be your setup issue for sure.
I am working on simple SIP-client Android app.
But when I try to register sipProfile on Server, I get errorCode = -9 and errorMessage= 0.
Here is my activity:
public SipManager sipManager;
private SipProfile sipProfile;
// here is the data, I've just erased it
private String USERNAME = "";
private String AUTHUSERNAME = "";
private String DOMAIN = "";
private String PASSWORD = "";
private int PORT = 5060;
public SipAudioCall call = null;
public String sipAddress = null;
private Button btnRegister, btnCloseProfile;
private TextView tvStatus;
public IncomingCallReceiver callReceiver;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnRegister = (Button) findViewById(R.id.btnRegister);
tvStatus = (TextView) findViewById(R.id.tvStatus);
btnCloseProfile = (Button) findViewById(R.id.btnCloseProfile);
btnRegister.setOnClickListener(register);
btnCloseProfile.setOnClickListener(closeProfile);
IntentFilter filter = new IntentFilter();
filter.addAction("android.SipDemo.INCOMING_CALL");
callReceiver = new IncomingCallReceiver();
this.registerReceiver(callReceiver, filter);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
View.OnClickListener closeProfile = new View.OnClickListener() {
#Override
public void onClick(View v) {
closeLocalProfile();
}
};
View.OnClickListener register = new View.OnClickListener() {
#Override
public void onClick(View v) {
initializeManager();
}
};
void initializeManager(){
if(sipManager == null) {
sipManager = SipManager.newInstance(this);
}
initializeLocalProfile();
}
#Override
protected void onStart() {
super.onStart();
initializeManager();
}
public void initializeLocalProfile(){
if (sipManager == null){
return;
}
if (sipProfile != null){
closeLocalProfile();
}
try {
SipProfile.Builder builder = new SipProfile.Builder(USERNAME, DOMAIN);
builder.setPassword(PASSWORD);
builder.setAuthUserName(AUTHUSERNAME);
sipProfile = builder.build();
Intent intent = new Intent();
intent.setAction("ru.tenet.apdu.INCOMING_CALL");
PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA);
sipManager.open(sipProfile, pi, null);
sipManager.setRegistrationListener(sipProfile.getUriString(), new SipRegistrationListener() {
#Override
public void onRegistering(String localProfileUri) {
updateStatus("Registering with SIP Server...");
}
#Override
public void onRegistrationDone(String localProfileUri, long expiryTime) {
updateStatus("Ready");
}
#Override
public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) {
updateStatus("Registration failed with error:\n" + SipErrorCode.toString(errorCode) +"\n"+errorMessage);
}
});
}
catch (SipException e){
e.printStackTrace();
updateStatus("SipException");
} catch (ParseException e) {
e.printStackTrace();
updateStatus("ParseException");
}
}
#Override
protected void onDestroy() {
super.onDestroy();
if (call != null) {
call.close();
}
closeLocalProfile();
if (callReceiver != null) {
this.unregisterReceiver(callReceiver);
}
}
public void closeLocalProfile() {
if (sipManager == null) {
return;
}
try {
if (sipProfile != null) {
sipManager.close(sipProfile.getUriString());
}
} catch (Exception ee) {
Log.d("StatusWindow/onDestroy", "Failed to close local profile.", ee);
}
}
void updateStatus(final String status){
Log.d("mylog","status = " +status);
runOnUiThread(new Runnable() {
#Override
public void run() {
tvStatus.setText(status);
}
});
}
public void updateStatus(SipAudioCall call) {
String useName = call.getPeerProfile().getDisplayName();
if(useName == null) {
useName = call.getPeerProfile().getUserName();
}
updateStatus(useName + "#" + call.getPeerProfile().getSipDomain());
}
And my Permissions:
<uses-permission android:name="android.permission.USE_SIP"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
If I try with following code:
sipManager.open(sipProfile, pi, null);
sipManager.register(sipProfile, 20, new SipRegistrationListener() {
#Override
public void onRegistering(String localProfileUri) {
updateStatus("Registering with SIP Server...");
}
#Override
public void onRegistrationDone(String localProfileUri, long expiryTime) {
updateStatus("Ready");
}
#Override
public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) {
updateStatus("Registration failed with error:\n" + SipErrorCode.toString(errorCode) +"\n"+errorMessage);
}
});
I get SipException:
android.net.sip.SipException: SipService.createSession() returns null
FIXED
It looks like one of the sip sessions has been frozen on device.
After physical reboot I got my registration
In case this error you need close local profile and repeat create session
manager.setRegistrationListener(me.getUriString(), new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
updateStatus("Registering with SIP Server...");
}
public void onRegistrationDone(String localProfileUri, long expiryTime) {
updateStatus("Ready");
}
public void onRegistrationFailed(String localProfileUri, int errorCode,
String errorMessage) {
if(errorCode == SipErrorCode.IN_PROGRESS) {
closeLocalProfile();
try {
manager.open(me, pi, null);
} catch (SipException e) {
e.printStackTrace();
}
}
}
});
After lot of searching and going through multiple stackoverflow answers and wasting 2 days on registration errors, here are the things that you should consider to get the registration done ! These worked for me. Reply to this answer if they work for you too :)
Check for the following your code:
First of all, check whether all required permissions are given or not
Use open method instead of register & close instead of unregister
Set your SipRegisterationListener after calling open method, pass null as a parameter in open method for listener and call sipManager.setRegisterationListener(listener) to set the listener.
Your domain must not include port number it should be simple server domain link ; For example com.google.com
First try running the app without setting the port number in SipProfile.Builder ; if that fails, add port manually using builder.setPort(xxxx)
Try changing the protocol. Currently only UDP & TCP are the options available as mentioned in this documentation
Check that your profile uri built is of the format sip:<username>#<domain>. For example if the username is abcd and domain is com.google.com, the SipProfile uri string should be sip:abcd#com.google.com
Try the following things if your android code is correct :
Check the username and password properly / try some other username and password. Before trying with other credentials, close the existing SipProfile until is is successfully closed.
Clear data of Phone Service system apps from your phone
Clear data of your developed SIP app also
Close any open / existing SIP accounts on the device from Phone > Settings > Calling Accouts > Sip Accounts;
Reboot your phone
I have an Elastix server, which is being used by my desktop calling app and Zoiper App perfectly for calling purposes. However my own app, which is using Android SIP is not working fine and I am unable to locate the real problem.
Whenever I call for profile registration, it gets failed and error message of REGISTRATION NOT RUNNING shows in the logs.
here is my code snippet:
public void InitializeProfile()
{
if (mSipManager == null)
{
return;
}
if (mSipProfile != null){
closeLocalProfile();
}
SipProfile.Builder builder = null;
try {
builder = new SipProfile.Builder(Username, Domain);
} catch (ParseException e) {
e.printStackTrace();
}
builder.setPassword(Password);
mSipProfile = builder.build();
Intent intent = new Intent();
intent.setAction("android.SipDemo.INCOMING_CALL");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA);
try {
mSipManager.open(mSipProfile, pendingIntent, null);
} catch (SipException e) {
Log.i("open", e.toString());
e.printStackTrace();
}
try {
mSipManager.setRegistrationListener(mSipProfile.getUriString(), new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
// updateStatus("Registering with SIP Server...");
Log.i("helloworld", "Registering with SIP Server...");
}
public void onRegistrationDone(String localProfileUri, long expiryTime) {
// updateStatus("Ready");
Log.i("helloworld", "Ready");
}
public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) {
// updateStatus("Registration failed. Please check settings.");
Log.i("helloworld", "Registration failed. Please check settings."+ errorMessage+ " " + Integer.toString(errorCode));
}
});
} catch (SipException e) {
e.printStackTrace();
}
}
I'm currently developing an application for making VoIP/SIP calls, but I don't know why I cannot make a call to a number using my program. I have a valid SIP server_id, password and domain. Using that domain call can be made. Programming code is given below. Can anyone help me out?
public class CallActivity extends Activity {
public String sipAddress = "nizamcs#sip2sip.info";
public SipManager manager = null;
public SipProfile me = null;
public SipAudioCall call = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.calling);
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 = "my_username";
String domain = "my_domain";
String password = "my_password";
if (username.length() == 0 || domain.length() == 0 || password.length() == 0) {
return;
}
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);
manager.setRegistrationListener(me.getUriString(), new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
Log.d("onRegistering", "Registering with SIP Server...");
}
public void onRegistrationDone(String localProfileUri, long expiryTime) {
Log.d("onRegistrationDone", "RegistrationDone..Ready");
}
public void onRegistrationFailed(String localProfileUri, int errorCode,
String errorMessage) {
Log.d("onRegistrationFailed", "RegistrationFailed");
}
});
} catch (ParseException pe) {
} catch (SipException se) {
}
initiateCall();
}
public void closeLocalProfile() {
if (manager == null) {
return;
}
try {
if (me != null) {
manager.close(me.getUriString());
}
} catch (Exception ee) {
Log.d("WalkieTalkieActivity/onDestroy",
"Failed to close local profile.", ee);
}
}
public void initiateCall() {
try {
SipAudioCall.Listener listener = new SipAudioCall.Listener() {
#Override
public void onCallEstablished(SipAudioCall call) {
call.startAudio();
call.setSpeakerMode(true);
call.toggleMute();
// updateStatus(call);
}
#Override
public void onCallEnded(SipAudioCall call) {
}
};
call = manager.makeAudioCall(me.getUriString(), sipAddress, listener, 300);
}
catch (Exception e) {
Log.i("WalkieTalkieActivity/InitiateCall", "Error when trying to close manager.", e);
if (me != null) {
try {
manager.close(me.getUriString());
} catch (Exception ee) {
Log.i("WalkieTalkieActivity/InitiateCall",
"Error when trying to close manager.", ee);
ee.printStackTrace();
}
}
if (call != null) {
call.close();
}
}
}
}
Please check if your request is being send by using wireshark and see the response you get from the sip server. By doing it you can make sure if the request is actually being send or not.