Android VOIP SipException: Failed to create SipSes

2019-04-09 08:00发布

Im trying to run a VOIP call using built in SIP on android 3.1. I have physical tablet device (galaxy Tab 10.1).

For testing purpose, I have created a project from SipDemo example - it works fine! (meaning my credentials are working and my device/network is fine).

my Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="modera.com.doorcontroller" android:versionCode="1" android:versionName="1.0">

    <application android:icon="@drawable/logoeditedsmall" android:label="@string/app_name" android:debuggable="true">
      <activity android:name="MainActivity" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>

      <activity android:name="CallActivity"></activity>

</application>

<uses-sdk android:minSdkVersion="11" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<uses-feature android:name="android.hardware.sip.voip" android:required="true" />
<uses-feature android:name="android.hardware.wifi" android:required="true" />
<uses-feature android:name="android.hardware.microphone" android:required="true" />

</manifest>

my backend code:

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

    if (me != null) {
        closeLocalProfile();
    }

    try {
        SipProfile.Builder builder = new SipProfile.Builder(username,
                domain);
        builder.setPassword(password);
        builder.setOutboundProxy(proxy);
        me = builder.build();

        manager.open(me);

        manager.setRegistrationListener(me.getUriString(),
                new SipRegistrationListener() {

                    @Override
                    public void onRegistering(String localProfileUri) {
                        Log.i("MY", "onRegistering");

                    }

                    @Override
                    public void onRegistrationDone(String localProfileUri,
                            long expiryTime) {
                        Log.i("MY", "onRegistrationDone");

                    }

                    @Override
                    public void onRegistrationFailed(
                            String localProfileUri, int errorCode,
                            String errorMessage) {
                        Log.i("MY", "onRegistrationFailed");

                    }
                });

    } catch (ParseException pe) {
        Log.e("MY", pe.toString());
    } catch (SipException se) {
        Log.e("MY", se.toString());
    }
}



public void initiateCall() {

    try {
        SipAudioCall.Listener listener = new SipAudioCall.Listener() {

            @Override
            public void onCallEstablished(SipAudioCall call) {
                call.startAudio();
                call.setSpeakerMode(true);
                call.toggleMute();
                Log.i("MY", "oonCallEstablished");
            }

            @Override
            public void onCallEnded(SipAudioCall call) {
                Log.i("MY", "onCallEnded");
            }
        };

        call = manager.makeAudioCall(me.getUriString(), sipAddress,
                listener, 30);

    } catch (Exception e) {
        Log.e("MY", e.toString());
        if (me != null) {
            try {
                manager.close(me.getUriString());
            } catch (Exception ee) {
                Log.e("MY", ee.toString());
            }
        }
        if (call != null) {
            call.close();
        }
    }
}

Running this code (at first I initalize, using initalizeManager and then I run initateCall) I receive an exception:

android.net.sip.SipException: Failed to create SipSession; network unavailable?

...and LogCat logs:

07-14 13:35:16.200: ERROR/SipService(364): openToMakeCalls()
07-14 13:35:16.200: ERROR/SipService(364): javax.sip.SipException: only creator can access the profile
07-14 13:35:16.200: ERROR/SipService(364):     at com.android.server.sip.SipService.createGroup(SipService.java:337)
07-14 13:35:16.200: ERROR/SipService(364):     at com.android.server.sip.SipService.open(SipService.java:185)
07-14 13:35:16.200: ERROR/SipService(364):     at android.net.sip.ISipService$Stub.onTransact(ISipService.java:58)
07-14 13:35:16.200: ERROR/SipService(364):     at android.os.Binder.execTransact(Binder.java:320)
07-14 13:35:16.200: ERROR/SipService(364):     at dalvik.system.NativeStart.run(Native Method)
07-14 13:35:16.200: WARN/SipService(364): only creator can set listener on the profile
07-14 13:35:16.230: WARN/SipService(364): only creator or radio can close this profile

Google hasn't given any results, because there just isnt enough data on Android 2.3+ SIP, so every suggestion you make helps me out a lot!

1条回答
放荡不羁爱自由
2楼-- · 2019-04-09 08:35

Problem solved: You can not call initiateCall() right after initializeManager(). You have to wait about 4 seconds when the SIP components have initialized.

EDIT- there seems to be still be some problem with SipManager registering: Calling User Not registered (403). Reinstalling app and rebooting device solves the problem.

查看更多
登录 后发表回答