实现SIP和语音调用android

时间:2015-01-16 00:56:01

标签: android sip

我试图在我的应用程序中使用SIP协议,我遵循了android文档和SIP演示项目但不幸的是我无法使用SIP我得到Registration Failed Error。这是 InitializeLocalProfile 功能:

public void initializeLocalProfile()  {
        if (manager == null) {
            return;
        }

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

        String username =  ((EditText)findViewById(R.id.SipUserName)).getText().toString();
        String domain = ((EditText) findViewById(R.id.SipDomain)).getText().toString();
        String password = ((EditText)findViewById(R.id.SipPassword)).getText().toString();    


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

                 Intent i = new Intent();
                 // I think Error is here or in one of the Next 3 Lines
                //Kontact is my project Name, I tried also com.example.kontact.INCOMING_CAL
                i.setAction("android.Kontact.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("Failure to Register...");
                    }
                });
        } catch (ParseException pe) {
            pe.printStackTrace();
            updateStatus("Connection Error.");
        } catch (SipException se) {
            se.printStackTrace();
            updateStatus("Connection error.");
        } catch (java.text.ParseException e) {
            e.printStackTrace();
        }
    }

这是清单文件:

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

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.USE_SIP" />
    <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-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />

    <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" />

    <application
        <receiver android:name=".IncomingCallReceiver" android:label="Call Receiver"/>
        <activity
            android:name=".SipActivity"
            android:label="@string/title_activity_sip" >
             <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

1 个答案:

答案 0 :(得分:0)

call = mSipManager.makeAudioCall(mSipProfile.getUriString(), "sip:" + num.getText().toString() + "@" + domain, listener, 30);

但是在关闭监听器之后调用它。