Good day.
I am trying to open the sip profile which is pre-registered already.
The profile is fully working if i download any other SIP application from Google Play, but when i try to initialize inside my code, i get the error registration not running
while opening the profile.
Anyway, here is the code of how i initialize and open the already registered SIP profile.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_SIP) != PermissionChecker.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.USE_SIP}, 0);
}
initSip();
}
private void initSip() {
if (mSipManager == null) {
mSipManager = SipManager.newInstance(this);
}
}
public void closeLocalProfile() {
if (mSipManager == null) {
return;
}
try {
if (mSipProfile != null) {
mSipManager.close(mSipProfile.getUriString());
}
} catch (Exception ee) {
ee.printStackTrace();
Log.d("faskjlfas", "Failed to close local profile.", ee);
}
}
And on click i open the local profile like this.
@OnClick(R.id.login)
public void loginClciked() {
closeLocalProfile();
profile = null;
try {
profile = new SipProfile.Builder(usernameEd.getText().toString(), "sip2sip.info");
} catch (ParseException e) {
e.printStackTrace();
}
profile.setPassword(passwordED.getText().toString());
mSipProfile = profile.build();
Intent intent = new Intent();
intent.setAction("android.SipDemo.INCOMING_CALL");
final PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA);
try {
mSipManager.open(mSipProfile, pendingIntent, new SipRegistrationListener() {
@Override
public void onRegistering(String localProfileUri) {
runOnUiThread(new Runnable() {
@Override
public void run() {
updateStatus("Registering with SIP Server...");
}
});
}
@Override
public void onRegistrationDone(String localProfileUri, long expiryTime) {
runOnUiThread(new Runnable() {
@Override
public void run() {
updateStatus("Ready");
}
});
}
@Override
public void onRegistrationFailed(String localProfileUri, int errorCode, final String errorMessage) {
runOnUiThread(new Runnable() {
@Override
public void run() {
updateStatus("Registration failed. Please check settings." + errorMessage);
}
});
}
});
} catch (SipException e) {
e.printStackTrace();
}
}
But as mentioned, the onRegistrationFailed
callback is being triggered with the message registration not running
. So any help will be appreciated.