Android VOIP SipException:无法创建SipSession

时间:2011-07-14 12:06:25

标签: android android-3.0-honeycomb voip sip

我试图在Android 3.1上使用内置SIP运行VOIP呼叫。我有物理平板设备(galaxy Tab 10.1)。

出于测试目的,我已经从SipDemo example创建了一个项目 - 它运行正常! (意思是我的凭据正常,我的设备/网络很好)。

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>

我的后端代码:

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();
        }
    }
}

运行此代码(首先我初始化,使用initalizeManager,然后运行initateCall)我收到一个异常:

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

...和LogCat日志:

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

谷歌没有给出任何结果,因为Android 2.3+ SIP上的数据不够,所以你提出的每一个建议都会帮助我很多!

1 个答案:

答案 0 :(得分:4)

问题已解决:您无法在initializeManager()之后立即调用initiateCall()。 SIP组件初始化后,您必须等待大约4秒钟。

编辑 - SipManager注册时似乎仍然存在一些问题:调用用户未注册(403)。重新安装应用程序并重新启动设备可以解决问题。