简体   繁体   中英

Impleminting SIP and Voice call android

I'm trying to use the SIP Protocol in my application, I followed the android documentation and the SIP demo Project but unfortunally I couldn't use SIP I get Registration Failed Error . This is the InitializeLocalProfile Function :

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

And this is the Manifest File :

<?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>
call = mSipManager.makeAudioCall(mSipProfile.getUriString(), "sip:" + num.getText().toString() + "@" + domain, listener, 30);

但是在关闭监听器之后调用此函数。

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