title: Android SipManager registration failed
body: <p>I'm following Google's guidelines to create in app SIP calls as in <a href="https://developer.android.com/guide/topics/connectivity/sip.html" rel="nofollow noreferrer">https://developer.android.com/guide/topics/connectivity/sip.html</a>
  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</p>
  
  <pre><code>@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();
      }
  }
  </code></pre>
  
  <p>Any help will be much appreciated.</p>