0

我正在尝试在 android LGP500 上构建一个 sip 应用程序。它有安卓版本 2.3.3。我用过 brekeke sip 服务器。android.jar 中也存在 android.net.sip。这表明谷歌服务已正确安装。甚至 zoiper 也在使用那部手机,所以我认为 voip 或 sip 服务器上没有问题。它仍然将 SipManager 显示为空。请帮忙。

代码:

主要活动:

    package com.example.ssiipp;

import android.net.ParseException;
import android.net.sip.SipAudioCall;
import android.net.sip.SipException;
import android.net.sip.SipManager;
import android.net.sip.SipProfile;
import android.net.sip.SipRegistrationListener;
import android.os.Bundle;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ToggleButton;
import java.lang.*;

public class MainActivity extends Activity implements View.OnTouchListener {

    public String sipAddress = null;
    public SipManager manager = null;
    public SipProfile me = null;
    public SipAudioCall call = null;
    //public IncomingCallReceiver callReceiver;

    private static final int CALL_ADDRESS = 1;
    private static final int SET_AUTH_INFO = 2;
    private static final int UPDATE_SETTINGS_DIALOG = 3;
    private static final int HANG_UP = 4;
    static EditText et1;
    EditText et2;
    static EditText et3;
    Button b1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        et1 = (EditText) findViewById(R.id.et);
        et2 = (EditText) findViewById(R.id.ett);
        et3 = (EditText) findViewById(R.id.ee);
        b1 = (Button) findViewById(R.id.btn);
        manager = SipManager.newInstance(this);
        initializeManager();
        et3.setText("1");

        try {
            ToggleButton pushToTalkButton = (ToggleButton) findViewById(R.id.tb);
            pushToTalkButton.setOnTouchListener(this);
            IntentFilter filter = new IntentFilter();
            filter.addAction("com.example.ssiipp.SIP_INCOMING_CALL");
            //et3.setText("11");
            //callReceiver = new IncomingCallReceiver();

            //what is sticky intent?
            //   this.registerReceiver(callReceiver, filter);
        } catch (Exception e) {
            et1.setText("ERROR" + e.getMessage());
        }
        //Context ct=getBaseContext();

        b1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                sipAddress = et2.getText().toString();
                initiateCall();
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void onStart() {
        super.onStart();
        // When we get back from the preference setting Activity, assume
        // settings have changed, and re-login with new auth info.
        //initializeManager();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (call != null) {
            call.close();
        }

        closeLocalProfile();


    }

    public void initializeManager() {

        if (manager == null) {
            manager = SipManager.newInstance(this);
            et1.setText("MNGR=" + manager);
        }

        initializeLocalProfile();
    }

    public void closeLocalProfile() {
        if (manager == null) {
            return;
        }
        try {
            if (me != null) {
                manager.close(me.getUriString());
            }
        } catch (Exception ee) {
            // Log.d("WalkieTalkieActivity/onDestroy", "Failed to close local profile.", ee);
        }
    }

    public void initializeLocalProfile() {
        if (manager == null) {
            //et1.setText("no");
            return;
        }

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

        String username = "1010";
        String domain = "192.168.3.12";
        String password = "1010";

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

            me = builder.build();

            Intent i = new Intent();
            i.setAction("com.example.ssiipp.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) {
                    et1.setText("Yes Registering with SIP Server...");
                }

                public void onRegistrationDone(String localProfileUri, long expiryTime) {
                    et1.setText("Ready");
                }

                public void onRegistrationFailed(String localProfileUri, int errorCode,
                    String errorMessage) {
                    et1.setText(me.getPassword() + me.getPort() + me.getUriString() + "Registration failed.  Please check settings.");
                }
            });
        } catch (ParseException pe) {
            et1.setText("Connection Error.1");
        } catch (SipException se) {
            et1.setText("Connection error.2");
        } catch (java.text.ParseException e) {
            e.printStackTrace();
            et1.setText("Connection error.3");
        }

    }

    public void initiateCall() {

        et1.setText(sipAddress);

        try {
            et1.setText("in");
            SipAudioCall.Listener listener = new SipAudioCall.Listener() {
                // Much of the client's interaction with the SIP Stack will
                // happen via listeners.  Even making an outgoing call, don't
                // forget to set up a listener to set things up once the call is established.
                @Override
                public void onCalling(SipAudioCall call) {
                    et1.setText("calling");
                }

                @Override
                public void onCallEstablished(SipAudioCall call) {
                    et1.setText("call1");
                    call.startAudio();
                    call.setSpeakerMode(true);
                    call.toggleMute();
                    et1.setText("call");
                }

                @Override
                public void onCallEnded(SipAudioCall call) {
                    et1.setText("Ready.");
                }
            };

            call = manager.makeAudioCall(me.getUriString(), et2.getText().toString(), listener, 30);
            // call = manager.makeAudioCall(me.getUriString(), (""+et2.getText()).trim(),   null, 200);
            // et1.setText(""+call.getPeerProfile());
        } catch (Exception e) {
            et1.setText("WalkieTalkieActivity/InitiateCall" + e.getMessage());

        }
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
        return false;
    }
    public static void pass(String str) {
        et3.setText(str);
    }

}

显现:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.ssiipp" android:versionCode="1" android:versionName="1.0">
  <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="18"/>
  <uses-permission android:name="android.permission.USE_SIP"/>
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.VIBRATE"/>
  <uses-permission android:name="android.permission.CONFIGURE_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.MODIFY_AUDIO_SETTINGS"/>
  <uses-feature android:name="android.software.sip" android:required="true"/>
  <uses-feature android:name="android.software.sip.voip" android:required="true"/>
  <uses-feature android:name="android.hardware.telephony" android:required="false"/>
  <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 android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
    <activity android:name="com.example.ssiipp.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>
    <receiver android:name=".IncomingCallReceiver" android:label="Call Receiver"/>
    <intent-filter>
      <action android:name="android.SipDemo.INCOMING_CALL"/>
    </intent-filter>
  </application>
</manifest>

日志文件:

05-03 16:06:53.539: I/ActivityManager(1568): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.ssiipp/.MainActivity } from pid 12990
05-03 16:06:53.659: D/KeyguardViewMediator(1568): <!>com.android.internal.policy.impl.KeyguardViewMediator 608<!> wakeWhenReadyLocked(3)
05-03 16:06:53.799: D/DATA(1670): <!>com.android.internal.telephony.DataServiceStateTracker 1075<!> [DSST] pollstate() : reason = data network state changed
05-03 16:06:53.809: D/[brighthy_log](1670): <!>com.android.internal.telephony.gsm.GsmServiceStateTracker 606<!> [CHOSH] ONS plmn :null
05-03 16:06:53.829: D/[brighthy_log](1670): <!>com.android.internal.telephony.gsm.GsmServiceStateTracker 608<!> [CHOSH][TIM BR] plmn from getOperatorAlphaLong:Vodafone IN
05-03 16:06:53.829: I/AMIT1(1670): <!>com.android.internal.telephony.gsm.GsmServiceStateTracker 802<!> SPN -2nd Block
05-03 16:06:53.829: D/AMITKUMAR[2nd Block](1670): <!>com.android.internal.telephony.gsm.GsmServiceStateTracker 803<!> currentLanguage: encurrentcountry: IN
05-03 16:06:53.839: I/hs(11044): <!>com.lge.android.calendarwidget.widget.UpdateService 359<!> android.intent.action.SCREEN_ON
05-03 16:06:53.839: I/hs(11044): <!>com.lge.android.calendarwidget.widget.UpdateService 360<!> Screen On!, try to request
05-03 16:06:53.849: I/AMITKUMAR[3rd Block](1670): <!>com.android.internal.telephony.gsm.GsmServiceStateTracker 872<!> SPN -3nd Block
05-03 16:06:53.859: D/AMITKUMAR[3rd Block](1670): <!>com.android.internal.telephony.gsm.GsmServiceStateTracker 874<!> operator: 40486
05-03 16:06:53.859: D/AMITKUMAR[3rd Block](1670): <!>com.android.internal.telephony.gsm.GsmServiceStateTracker 879<!> mcc: 404
05-03 16:06:53.859: I/hs(11044): <!>com.lge.android.calendarwidget.widget.UpdateService 169<!> sCalendarMap, containsKey appWidgetId : 1 is exist in map
05-03 16:06:53.859: D/hs(11044): <!>com.lge.android.calendarwidget.widget.CalendarWidgetProvider 313<!> Provider buildUpdate
05-03 16:06:53.859: D/hs(11044): <!>com.lge.android._.LgeAndyFlex 28<!> opCode: [OPEN]
05-03 16:06:53.869: D/hs(11044): <!>com.lge.android.calendarwidget.view.MonthCalendarView 185<!> FirstDayTime1
05-03 16:06:53.869: D/hs(11044): <!>com.lge.android.calendarwidget.view.MonthCalendarView 200<!> FirstWeekDayTime28
05-03 16:06:53.869: D/AMITKUMAR[3rd Block](1670): <!>com.android.internal.telephony.gsm.GsmServiceStateTracker 880<!> mnc: 86
05-03 16:06:53.869: D/DATA(1670): <!>com.android.internal.telephony.DataServiceStateTracker 381<!> **DATAServiceStateTracker***handlePollStateResult()**simNumeric==40486
05-03 16:06:53.879: D/hs(11044): <!>com.lge.android.calendarwidget.data.DayEvents 80<!> mStartJulianDay : 2456776mEndJulianDay : 2456817
05-03 16:06:53.879: D/DATA(1670): <!>com.android.internal.telephony.DataServiceStateTracker 382<!> **DATAServiceStateTracker***handlePollStateResult()**operatorNumeric==40486
05-03 16:06:53.879: D/DATA(1670): <!>com.android.internal.telephony.DataServiceStateTracker 389<!> **DATAServiceStateTracker***handlePollStateResult()**=equalsMnc===true
05-03 16:06:53.879: D/DATA(1670): <!>com.android.internal.telephony.DataServiceStateTracker 1075<!> [DSST] Poll ServiceState done: oldSS=[1 home null null null  GPRS CSS not supported -1 -1RoamInd: -1DefRoamInd: -1EmergOnly: false] newSS=[1 home null null null  GPRS CSS not supported -1 -1RoamInd: -1DefRoamInd: -1EmergOnly: false]
05-03 16:06:53.899: D/StatusBarPolicy(30405): [BRIGHTHY] 0. mDataNetType: 2
05-03 16:06:53.899: D/StatusBarPolicy(30405): [BRIGHTHY] curNetwork=40486 curHPLMN=40486
05-03 16:06:53.939: D/hs(11044): <!>com.lge.android.calendarwidget.view.MonthCalendarView 259<!> buildMonthViewDate : May 2014
05-03 16:06:55.129: E/MediaPlayerService(1462): [MediaPlayerService::Client::setDataSource]player type = 4
05-03 16:06:55.159: E/MediaPlayerService(1462): [MediaPlayerService::Client::setDataSource]player type = 4
05-03 16:06:55.219: I/#LGIME(1661): <!>com.jungle.android.utils.Glog 32<!> ### onFinishInput
05-03 16:06:55.219: I/#LGIME(1661): <!>com.jungle.android.utils.Glog 32<!> #### onStartInput: restarting=false, fieldId=2131230721
05-03 16:06:55.219: W/InputManagerService(1568): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40a1ea50
05-03 16:06:55.519: W/AudioFlinger(1462): write blocked for 283 msecs, 718 delayed writes, thread 0xce08
05-03 16:06:55.689: E/Andy_LockScreen(1568): <!>com.android.internal.policy.impl.Andy_LockScreen 1083<!> [BTUI] ### LockScreen : isOpen(false)
05-03 16:06:59.889: D/StatusBarPolicy(30405): [BRIGHTHY] 0. mDataNetType: 2
05-03 16:06:59.889: D/StatusBarPolicy(30405): [BRIGHTHY] curNetwork=40486 curHPLMN=40486
05-03 16:07:00.029: I/hs(11044): <!>com.lge.android.calendarwidget.widget.UpdateService 321<!> android.intent.action.TIME_TICK
05-03 16:07:02.899: D/StatusBarPolicy(30405): [BRIGHTHY] 0. mDataNetType: 2
05-03 16:07:02.899: D/StatusBarPolicy(30405): [BRIGHTHY] curNetwork=40486 curHPLMN=40486
05-03 16:07:07.479: I/ActivityManager(1568): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.ssiipp/.MainActivity } from pid 13025
05-03 16:07:12.429: I/ActivityManager(1568): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.lge.launcher/.Launcher } from pid 1568
05-03 16:07:12.939: D/StatusBarPolicy(30405): [BRIGHTHY] 0. mDataNetType: 2
05-03 16:07:12.939: D/StatusBarPolicy(30405): [BRIGHTHY] curNetwork=40486 curHPLMN=40486
05-03 16:07:24.949: I/ActivityManager(1568): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.ssiipp/.MainActivity } from pid 13056
05-03 16:07:30.959: D/StatusBarPolicy(30405): [BRIGHTHY] 0. mDataNetType: 2
05-03 16:07:30.959: D/StatusBarPolicy(30405): [BRIGHTHY] curNetwork=40486 curHPLMN=40486
05-03 16:07:33.949: D/StatusBarPolicy(30405): [BRIGHTHY] 0. mDataNetType: 2
05-03 16:07:33.949: D/StatusBarPolicy(30405): [BRIGHTHY] curNetwork=40486 curHPLMN=40486
05-03 16:07:39.939: D/StatusBarPolicy(30405): [BRIGHTHY] 0. mDataNetType: 2
05-03 16:07:39.939: D/StatusBarPolicy(30405): [BRIGHTHY] curNetwork=40486 curHPLMN=40486
05-03 16:07:41.069: I/ActivityManager(1568): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.ssiipp/.MainActivity } from pid 13089
05-03 16:07:41.269: I/#LGIME(1661): <!>com.jungle.android.utils.Glog 32<!> ### onFinishInput
05-03 16:07:41.279: I/#LGIME(1661): <!>com.jungle.android.utils.Glog 32<!> #### onStartInput: restarting=false, fieldId=2131230721
05-03 16:07:41.519: I/ActivityManager(1568): <!>com.android.server.am.ActivityRecord 444<!> Displayed com.example.ssiipp/.MainActivity: +401ms
05-03 16:07:42.949: D/StatusBarPolicy(30405): [BRIGHTHY] 0. mDataNetType: 2
05-03 16:07:42.949: D/StatusBarPolicy(30405): [BRIGHTHY] curNetwork=40486 curHPLMN=40486
05-03 16:07:54.949: D/StatusBarPolicy(30405): [BRIGHTHY] 0. mDataNetType: 2
05-03 16:07:54.949: D/StatusBarPolicy(30405): [BRIGHTHY] curNetwork=40486 curHPLMN=40486
05-03 16:08:00.039: I/hs(11044): <!>com.lge.android.calendarwidget.widget.UpdateService 321<!> android.intent.action.TIME_TICK
05-03 16:08:00.549: I/hs(11044): <!>com.lge.android.calendarwidget.widget.UpdateService 365<!> android.intent.action.SCREEN_OFF
05-03 16:08:00.549: I/hs(11044): <!>com.lge.android.calendarwidget.widget.UpdateService 366<!> Screen Off!, sAppWidgetIds clearing..
05-03 16:08:05.499: E/Andy_LockScreen(1568): <!>com.android.internal.policy.impl.Andy_LockScreen 1083<!> [BTUI] ### LockScreen : isOpen(true)

实际上我遇到了新问题:我的 lgp500 不支持 voip 和 sip。请告诉我在哪里测试我的应用程序。我也试过亚行。但它不起作用。显示:无法连接。连ping都连接不上。请帮忙。

4

2 回答 2

0

问题是并非所有设备都支持 Android SDK。
您可以先检查当前设备是否支持它:

 if(SipManager.isVoipSupported(getApplicationContext())){
     Log.d("VOIP:", "Supported!");
 }
 else{
     Log.d("VOIP:", "Not Supported");
 }
 if(SipManager.isApiSupported(getApplicationContext())){
     Log.d("API:", "Supported!");
 }
 else{
     Log.d("API:","NotSupported!");
 }

为避免这一警告,您可以使用 3rd 方 API,例如Doubango

来源Android 上的 SIP

于 2018-05-18T18:00:58.180 回答
-1

带有 SIP 选项的 NAT 路由器碰巧阻止了端口 5060 上的内部 SIP

于 2015-04-20T11:01:04.867 回答