Android SIP演示显示注册失败。请检查设置

Android SIP演示显示注册失败。请检查设置,android,sip,Android,Sip,我想通过互联网进行应用到应用的音频通话。首先我用了这个例子 使用SINCH构建一个简单的ANDROID VOIP呼叫应用程序 通过此代码,我们可以进行应用程序到应用程序的音频通话。但他们会在几天后收取一定的费用 然后我得到了名为SIP(会话初始化协议)的免费api 我从Github获得了SipDemo示例代码。我在中创建了SIP帐户 www.getonsip.com获取SIP地址、域和SIP密码。我也用了同样的方法 我的首选项中的凭据。运行时,其显示注册失败。请检查设置。如何解决此错误 步行对话

我想通过互联网进行应用到应用的音频通话。首先我用了这个例子

使用SINCH构建一个简单的ANDROID VOIP呼叫应用程序

通过此代码,我们可以进行应用程序到应用程序的音频通话。但他们会在几天后收取一定的费用

然后我得到了名为SIP(会话初始化协议)的免费api

我从Github获得了SipDemo示例代码。我在中创建了SIP帐户

www.getonsip.com获取SIP地址、域和SIP密码。我也用了同样的方法

我的首选项中的凭据。运行时,其显示
注册失败。请检查设置。
如何解决此错误

步行对话活动

public class WalkieTalkieActivity extends Activity implements View.OnTouchListener {
    public String sipAddress = null;
    public SipManager manager = null;
    public SipProfile me = null;
    public SipAudioCall call = null;
    public IncomingCallReceiver callReceiver;
    private static final int CALL_ADDRESS = 1;
    private static final int SET_AUTH_INFO = 2;
    private static final int UPDATE_SETTINGS_DIALOG = 3;
    private static final int HANG_UP = 4;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.walkietalkie);
        ToggleButton pushToTalkButton = (ToggleButton) findViewById(R.id.pushToTalk);
        pushToTalkButton.setOnTouchListener(this);
        // Set up the intent filter.  This will be used to fire an
        // IncomingCallReceiver when someone calls the SIP address used by this
        // application.
        IntentFilter filter = new IntentFilter();
        filter.addAction("android.SipDemo.INCOMING_CALL");
        callReceiver = new IncomingCallReceiver();
        this.registerReceiver(callReceiver, filter);
        // "Push to talk" can be a serious pain when the screen keeps turning off.
        // Let's prevent that.
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        initializeManager();
    }

    @Override
    public void onStart() {
        super.onStart();
        // When we get back from the preference setting Activity, assume
        // settings have changed, and re-login with new auth info.
        initializeManager();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (call != null) {
            call.close();
        }
        closeLocalProfile();
        if (callReceiver != null) {
            this.unregisterReceiver(callReceiver);
        }
    }

    public void initializeManager() {
        if (manager == null) {
            manager = SipManager.newInstance(this);
        }
        initializeLocalProfile();
    }

    /**
     * Logs you into your SIP provider, registering this device as the location to
     * send SIP calls to for your SIP address.
     */
    public void initializeLocalProfile() {
        if (manager == null) {
            return;
        }
        if (me != null) {
            closeLocalProfile();
        }
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
        String username = prefs.getString("namePref", "");
        String domain = prefs.getString("domainPref", "");
        String password = prefs.getString("passPref", "");
        Log.i("getting preferrences", String.valueOf(username));
        Log.i("getting preferrences", String.valueOf(domain));
        Log.i("getting preferrences", String.valueOf(password));

        if (username.length() == 0 || domain.length() == 0 || password.length() == 0) {
            showDialog(UPDATE_SETTINGS_DIALOG);
            return;
        }
        try {
            SipProfile.Builder builder = new SipProfile.Builder(username, domain);
            builder.setPassword(password);
            //builder.setProtocol("UDP");
            me = builder.build();
            Intent i = new Intent();
            i.setAction("android.SipDemo.INCOMING_CALL");
            PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, Intent.FILL_IN_DATA);
            manager.open(me, pi, null);
            // This listener must be added AFTER manager.open is called,
            // Otherwise the methods aren't guaranteed to fire.
            manager.setRegistrationListener(me.getUriString(), new SipRegistrationListener() {
                public void onRegistering(String localProfileUri) {
                    updateStatus("Registering with SIP Server...");
                }

                public void onRegistrationDone(String localProfileUri, long expiryTime) {
                    updateStatus("Ready");
                }

                public void onRegistrationFailed(String localProfileUri, int errorCode,
                                                 String errorMessage) {
                    updateStatus("Registration failed.  Please check settings.");
                }
            });
        } catch (ParseException pe) {
            updateStatus("Connection Error.");
        } catch (SipException se) {
            updateStatus("Connection error.");
        }
    }

    /**
     * Closes out your local profile, freeing associated objects into memory
     * and unregistering your device from the server.
     */
    public void closeLocalProfile() {
        if (manager == null) {
            return;
        }
        try {
            if (me != null) {
                manager.close(me.getUriString());
            }
        } catch (Exception ee) {
            Log.d("WalkieTalkieActivity/onDestroy", "Failed to close local profile.", ee);
        }
    }

    /**
     * Make an outgoing call.
     */
    public void initiateCall() {
        updateStatus(sipAddress);
        try {
            SipAudioCall.Listener listener = new SipAudioCall.Listener() {
                // Much of the client's interaction with the SIP Stack will
                // happen via listeners.  Even making an outgoing call, don't
                // forget to set up a listener to set things up once the call is established.
                @Override
                public void onCallEstablished(SipAudioCall call) {
                    call.startAudio();
                    call.setSpeakerMode(true);
                    call.toggleMute();
                    updateStatus(call);
                }

                @Override
                public void onCallEnded(SipAudioCall call) {
                    updateStatus("Ready.");
                }
            };
            call = manager.makeAudioCall(me.getUriString(), sipAddress, listener, 30);
        } catch (Exception e) {
            Log.i("WalkieTalkieActivity/InitiateCall", "Error when trying to close manager.", e);
            if (me != null) {
                try {
                    manager.close(me.getUriString());
                } catch (Exception ee) {
                    Log.i("WalkieTalkieActivity/InitiateCall",
                            "Error when trying to close manager.", ee);
                    ee.printStackTrace();
                }
            }
            if (call != null) {
                call.close();
            }
        }
    }

    /**
     * Updates the status box at the top of the UI with a messege of your choice.
     *
     * @param status The String to display in the status box.
     */
    public void updateStatus(final String status) {
        // Be a good citizen.  Make sure UI changes fire on the UI thread.
        this.runOnUiThread(new Runnable() {
            public void run() {
                TextView labelView = (TextView) findViewById(R.id.sipLabel);
                labelView.setText(status);
            }
        });
    }

    /**
     * Updates the status box with the SIP address of the current call.
     *
     * @param call The current, active call.
     */
    public void updateStatus(SipAudioCall call) {
        String useName = call.getPeerProfile().getDisplayName();
        if (useName == null) {
            useName = call.getPeerProfile().getUserName();
        }
        updateStatus(useName + "@" + call.getPeerProfile().getSipDomain());
    }

    /**
     * Updates whether or not the user's voice is muted, depending on whether the button is pressed.
     *
     * @param v     The View where the touch event is being fired.
     * @param event The motion to act on.
     * @return boolean Returns false to indicate that the parent view should handle the touch event
     * as it normally would.
     */
    public boolean onTouch(View v, MotionEvent event) {
        if (call == null) {
            return false;
        } else if (event.getAction() == MotionEvent.ACTION_DOWN && call != null && call.isMuted()) {
            call.toggleMute();
        } else if (event.getAction() == MotionEvent.ACTION_UP && !call.isMuted()) {
            call.toggleMute();
        }
        return false;
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, CALL_ADDRESS, 0, "Call someone");
        menu.add(0, SET_AUTH_INFO, 0, "Edit your SIP Info.");
        menu.add(0, HANG_UP, 0, "End Current Call.");
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case CALL_ADDRESS:
                showDialog(CALL_ADDRESS);
                break;
            case SET_AUTH_INFO:
                updatePreferences();
                break;
            case HANG_UP:
                if (call != null) {
                    try {
                        call.endCall();
                    } catch (SipException se) {
                        Log.d("WalkieTalkieActivity/onOptionsItemSelected",
                                "Error ending call.", se);
                    }
                    call.close();
                }
                break;
        }
        return true;
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
            case CALL_ADDRESS:
                LayoutInflater factory = LayoutInflater.from(this);
                final View textBoxView = factory.inflate(R.layout.call_address_dialog, null);
                return new AlertDialog.Builder(this)
                        .setTitle("Call Someone.")
                        .setView(textBoxView)
                        .setPositiveButton(
                                android.R.string.ok, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int whichButton) {
                                        EditText textField = (EditText)
                                                (textBoxView.findViewById(R.id.calladdress_edit));
                                        sipAddress = textField.getText().toString();
                                        initiateCall();
                                    }
                                })
                        .setNegativeButton(
                                android.R.string.cancel, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int whichButton) {
                                        // Noop.
                                    }
                                })
                        .create();
            case UPDATE_SETTINGS_DIALOG:
                return new AlertDialog.Builder(this)
                        .setMessage("Please update your SIP Account Settings.")
                        .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                updatePreferences();
                            }
                        })
                        .setNegativeButton(
                                android.R.string.cancel, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int whichButton) {
                                        // Noop.
                                    }
                                })
                        .create();
        }
        return null;
    }

    public void updatePreferences() {
        Intent settingsActivity = new Intent(getBaseContext(),
                SipSettings.class);
        startActivity(settingsActivity);
    }
}
输入呼叫接收器

public class IncomingCallReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        SipAudioCall incomingCall = null;
        try {

            SipAudioCall.Listener listener = new SipAudioCall.Listener() {
                @Override
                public void onRinging(SipAudioCall call, SipProfile caller) {
                    try {
                        call.answerCall(30);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };

            WalkieTalkieActivity wtActivity = (WalkieTalkieActivity) context;

            incomingCall = wtActivity.manager.takeAudioCall(intent, listener);
            incomingCall.answerCall(30);
            incomingCall.startAudio();
            incomingCall.setSpeakerMode(true);
            if (incomingCall.isMuted()) {
                incomingCall.toggleMute();
            }

            wtActivity.call = incomingCall;

            wtActivity.updateStatus(incomingCall);

        } catch (Exception e) {
            if (incomingCall != null) {
                incomingCall.close();
            }
        }
    }

}
SipSettings

public class SipSettings extends PreferenceActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
// Note that none of the preferences are actually defined here.
// They're all in the XML file res/xml/preferences.xml.
   super.onCreate(savedInstanceState);
   addPreferencesFromResource(R.xml.preferences);

   }
}
preferences.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen   xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:name="SIP Username"
android:summary="Username for your SIP Account"
android:defaultValue=""
android:title="Enter Username"
android:key="namePref" />
<EditTextPreference
android:name="SIP Domain"
android:summary="Domain for your SIP Account"
android:defaultValue=""
android:title="Enter Domain"
android:key="domainPref" />
<EditTextPreference
android:name="SIP Password"
android:summary="Password for your SIP Account"
android:defaultValue=""
android:title="Enter Password"
android:key="passPref"
android:password="true" />

Logcat

06-02 17:03:40.787 29075-29075/?I/art:延迟启用Xcheck:jni 06-02 17:03:40.828 29075-29075/com.example.dekrinssoft.sipdemo D/LenovoAppIconTheme:额外资源;清洁卫生;清除缓存。。 06-02 17:03:40.833 29075-29075/com.example.dekrinssoft.sipdemod/Proxy:setHttpRequestCheckHandler 06-02 17:03:40.835 29075-29075/com.example.dekrinssoft.sipdemo I/art:jiangtaottt OpenDexFilesFromOat open_oat_file.get()==nullptr/data/app/com.example.dekrinssoft.sipdemo-2/base.apk 06-02 17:03:40.836 29075-29075/com.example.devrinssoft.sipdemo I/art:Jiangtaott OpenDexFilesFromOat_location==nullptr/data/app/com.example.devrinssoft.sipdemo-2/base.apk 06-02 17:03:40.836 29075-29075/com.example.devrinssoft.sipdemo I/art:Jiangtaott OpenDexFilesFromOat LoadMultiDexFilesFromOatFile success/data/app/com.example.devrinssoft.sipdemo-2/base.apk 06-02 17:03:40.836 29075-29075/com.example.dekrinssoft.sipdemo E/System:elements.add:/data/app/com.example.dekrinssoft.sipdemo-2/base.apk/data/app/com.example.dekrinssoft.sipdemo-2/base.apk/data/app/com.example.dekrinssoft.sipdemo-2/base.apk 06-02 17:03:40.855 29075-29075/com.example.dekrinssoft.sipdemo D/wangcy9:setStatusIcon出现错误主题! 06-02 17:03:40.908 29075-29094/com.example.dekrinssoft.sipdemo I/art:背景部分并发标记扫描GC释放92(16KB)AllocSpace对象,0(0B)LOS对象,39%空闲,7MB/11MB,暂停5.281ms,总计18.292ms 06-02 17:03:41.028 29075-29075/com.example.devrinssoft.sipdemo I/获得优先权:devrinssoft 06-02 17:03:41.028 29075-29075/com.example.dekrinssoft.sipdemo I/获取优惠:getonsip.com 06-02 17:03:41.028 29075-29075/com.example.dekrinssoft.sipdemo I/获得优先权:HUmjMBDnbtGdepLD 06-02 17:03:41.071 29075-29075/com.example.devrinssoft.sipdemo I/获得优先权:devrinssoft 06-02 17:03:41.071 29075-29075/com.example.dekrinssoft.sipdemo I/获得优先权:getonsip.com 06-02 17:03:41.071 29075-29075/com.example.dekrinssoft.sipdemo I/获得优先权:HUmjMBDnbtGdepLD 06-02 17:03:41.084 29075-29075/com.example.devrinssoft.sipdemo I/ViewRootImpl:CPU呈现VSync enable=true 06-02 17:03:41.085 29075-29116/com.example.dekrinssoft.sipdemo D/OpenGLRenderer:使用EGL\u交换\u行为\u保留:true 06-02 17:03:41.093 29075-29075/com.example.dekrinssoft.sipdemod/Atlas:正在验证地图。。。 06-02 17:03:41.147 29075-29116/com.example.dekrinssoft.sipdemo I/Adreno EGL::EGL1.4高通公司构建:非确定性的msm8916\u 64\u LA.BR.1.2.4\u RB1\u发布版(Ibddc658e36) 06-02 17:03:41.147 29075-29116/com.example.dekrinssoft.sipdemo I/Adreno EGL:OpenGL ES着色器编译器版本:E031.25.03.04 06-02 17:03:41.147 29075-29116/com.example.dekrinssoft.sipdemo I/Adreno EGL:建造日期:2015年8月9日星期二 06-02 17:03:41.147 29075-29116/com.example.dekrinssoft.sipdemo I/Adreno EGL:本地分支机构: 06-02 17:03:41.147 29075-29116/com.example.dekrinssoft.sipdemo I/Adreno EGL:远程分支:quic/LA.BR.1.2.4_rb1.17 06-02 17:03:41.147 29075-29116/com.example.dekrinssoft.sipdemo I/Adreno EGL:本地补丁程序:无 06-02 17:03:41.147 29075-29116/com.example.dekrinssoft.sipdemo I/Adreno EGL:重构分支:无 06-02 17:03:41.148 29075-29116/com.example.devrinssoft.sipdemo I/OpenGLRenderer:Initialized EGL,version1.4 06-02 17:03:41.170 29075-29116/com.example.devrinssoft.sipdemo D/OpenGLRenderer:启用调试模式0 06-02 17:03:41.173 29075-29116/com.example.dekrinssoft.sipdemo I/qdutils:PartialUpdate状态:已禁用 06-02 17:03:41.173 29075-29116/com.example.dekrinssoft.sipdemo I/qdutils:左对齐:0 06-02 17:03:41.173 29075-29116/com.example.devrinssoft.sipdemo I/qdutils:Width Align:0 06-02 17:03:41.173 29075-29116/com.example.dekrinssoft.sipdemo I/qdutils:Top Align:0 06-02 17:03:41.173 29075-29116/com.example.dekrinssoft.sipdemo I/qdutils:高度对齐:0 06-02 17:03:41.173 29075-29116/com.example.dekrinssoft.sipdemo I/qdutils:最小ROI宽度:0 06-02 17:03:41.173 29075-29116/com.example.dekrinssoft.sipdemo I/qdutils:Min ROI高度:0 06-02 17:03:41.173 29075-29116/com.example.dekrinssoft.sipdemo I/qdutils:需要ROI合并:0 06-02 17:03:41.173 29075-29116/com.example.devrinssoft.sipdemo I/qdutils:动态Fps:禁用 06-02 17:03:41.173 29075-29116/com.example.devrinssoft.sipdemo I/qdutils:Min面板fps:0 06-02 17:03:41.173 29075-29116/com.example.dekrinssoft.sipdemo I/qdutils:Max Panel fps:0 06-02 17:03:41.229 29075-29075/com.example.devrinssoft.sipdemo W/IInputConnectionWrapper:showStatusIcon on inactive InputConnection 06-02 17:03:41.230 29075-29075/com.example.dekrinssoft.sipdemo I/Timeline:Timeline:Activity\u idle id:android.os。BinderProxy@2dcb8695时间:13337352 06-02 17:03:42.013 29075-29075/com.example.devrinssoft.sipdemo I/获得优先权:devrinssoft 06-02 17:03:42.013 29075-29075/com.example.dekrinssoft.sipdemo I/获取偏好:getonsip.com 06-02 17:03:42.013 29075-29075/com.example.dekrinssoft.sipdemo I/获得优先权:HUmjMBDnbtGdepLD 06-02 17:03:42.099 29075-29075/com.example。