2017-03-06 118 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通的,但註冊端口號未打開。

我不認爲這是代碼問題。這肯定是你的設置問題。