简体   繁体   English

Android SipManager注册失败

[英]Android SipManager registration failed

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 我遵循Google的指南,在https://developer.android.com/guide/topics/connectivity/sip.html中创建应用SIP呼叫。我在sip.zadarma.com上创建了一个测试帐户,该帐户与SIP客户端配合使用我从Google Play下载但是当我尝试在我的应用中注册时,我得到:onRegistrationFailed errorCode = -4 errorMessage:注册未运行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. 在尝试使用SipClient代码之前,应先尝试以下解决方案来测试注册服务器。

  1. Try runnig any VoIP SoftPhone client to check your server, if its not working then debug that first ie PortNo/IP address issue. 尝试运行任何VoIP SoftPhone客户端来检查您的服务器,如果它不工作然后首先调试即PortNo / IP地址问题。
  2. If step one is working then try running Wireshark on server to track reply from incoming REGISTRATION Request from client. 如果第一步正在运行,则尝试在服务器上运行Wireshark以跟踪来自客户端的传入REGISTRATION请求的回复。

Although from "Error logs " from your text means ie IP address is pingable but Registration Port No is not opened. 虽然来自文本的“错误日志”表示IP地址可ping,但未打开注册端口号。

I don't think this is code issue. 我不认为这是代码问题。 It must be your setup issue for sure. 肯定是你的设置问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM