2017-03-06 138 views
0

我遵循Google的指导原则创建应用程序SIP电话,如https://developer.android.com/guide/topics/connectivity/sip.html 我在sip.zadarma.com上创建了一个测试帐户,该帐户适用于从Google Play下载的SIP客户端,但是当我尝试它在我的应用程序注册,我得到: onRegistrationFailed错误码= -4的errorMessage:注册没有运行 onRegistrationFailed错误码= -9的errorMessage:0Android SipManager注册失败

@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(); 
    } 
} 

任何帮助将非常感激。

回答

0

甚至在查看SipClient的代码之前,应该先尝试以下解决方案以测试您的注册服务器。

  1. 尝试运行任何VoIP软电话客户端来检查您的服务器,如果它不工作,然后调试第一个,即PortNo/IP地址问题。
  2. 如果第一步工作正常,则尝试在服务器上运行Wireshark以跟踪来自客户端的传入REGISTRATION请求的回复。

尽管来自文本的“错误日志”表示IP地址是可ping通的,但注册端口号未打开。

我不认为这是代码问题。这肯定是你的设置问题。