简体   繁体   中英

SIP register twice on android

I tried to write a Simple SIP application on android. I am using android API 19 and using asterisk as SIP server. However I found that every time I perform a SipManager.open(), it will register twice. When I make a call, two channels calling out.

My code as below:

                Intent intent = new Intent();
                intent.setAction(ACTION_INCOMING_CALL);
                PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA);

                if (mSipManager == null) {
                    mSipManager = SipManager.newInstance(this);
                }
                SipProfile.Builder builder = new SipProfile.Builder("<some sip id>", SIP_SERVER);
                builder.setPassword("<sip password>");

                mSipProfile = builder.build();
                mSipManager.close(mSipProfile.getUriString());

                mSipManager.open(mSipProfile, pendingIntent, null);

                mSipManager.setRegistrationListener(mSipProfile.getUriString(), new SipRegistrationListener() {

                    public void onRegistering(String localProfileUri) {
                        updateStatus("Registering");
                        Log.d("SipActivity", "Registering with SIP Server...");
                    }

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

                    public void onRegistrationFailed(String localProfileUri, int errorCode,
                        String errorMessage) {
                        updateStatus("Registration failed." + errorCode + " >>>" + errorMessage);
                        Log.d("SipActivity", "Registration failed.  Please check settings." + errorMessage);
                    }
                });

I had put log to make sure I call the open once but the logs showed "Registering with SIP server" twice and "Ready" twice.

I found the reason why it register twice. After I log the expiryTime on onRegistrationDone, the first event is -1 which mean the session had expired. So, due to autoRegister flag is true, it will register again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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