562935844@qq.com
2023-09-05 98340bb2bbd3b0c8b877c7d3314023c40f942c02
HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java
@@ -1,7 +1,11 @@
package com.hdl.hdllinphonesdk;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;
import android.view.TextureView;
import android.widget.Toast;
@@ -66,6 +70,7 @@
    private String mUsername, mPassword, mServerIP;
    //    private TextureView mRenderingView, mPreviewView;
    private boolean isAutoJumpCallView;//是否自动跳转呼叫页面
    private String intercomeType;
    private HDLLinphoneKit() {
@@ -196,6 +201,24 @@
        }
    }
    private HDLLinphoneService mService;
    private final ServiceConnection connection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder ibinder) {
            HDLLinphoneService.LinphoneBinder binder = (HDLLinphoneService.LinphoneBinder) ibinder;
            mService = binder.getService();
            //初始化
            mService.initCore();
        }
        @Override
        public void onServiceDisconnected(ComponentName name) {
            mService = null;
        }
    };
    /**
     * 开启服务
     *
@@ -206,12 +229,8 @@
            if (!HDLLinphoneService.isReady()) {
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.setClass(context, HDLLinphoneService.class);
                context.startService(intent);
//                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//                    context.startForegroundService(intent);//解决android8.0以上无法启动服务的问题
//                } else {
//                    context.startService(intent);
//                }
                context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
            }
        } catch (Exception e) {
            e.printStackTrace();
@@ -251,7 +270,12 @@
        mUsername = username;
        mPassword = password;
        mServerIP = serverIP;
        intercomeType = inter_type;
        login(inter_type);
    }
    public String getIntercomeType() {
        return intercomeType;
    }
    /**
@@ -352,6 +376,8 @@
     * 登录 SIP 服务器
     */
    private void loginToServer(String inter_type) {
        Log.e("==========", "loginToServer: ");
        try {
            if (mUsername == null || mPassword == null || mServerIP == null) {
                throw new RuntimeException("The sip account is not configured.");
@@ -380,7 +406,7 @@
        Core mLinphoneCore = HDLLinphoneService.getCore();
        if (mLinphoneCore == null) return;
        AuthInfo authInfo = Factory.instance().createAuthInfo(name, null, password, null, null, host);
        AuthInfo authInfo = Factory.instance().createAuthInfo(name, name, password, null, null, host);
        AccountCreator mAccountCreator = mLinphoneCore.createAccountCreator(null);
        mAccountCreator.setUsername(name);
        mAccountCreator.setDomain(host);
@@ -419,6 +445,7 @@
        prxCfg.setQualityReportingCollector(null);
        prxCfg.setQualityReportingInterval(0);
        prxCfg.enableRegister(true);
        //全视通需要设置固定代理服务器ip
        prxCfg.setServerAddr("sip:139.159.157.75:46000;transport=udp");
        mLinphoneCore.addProxyConfig(prxCfg);//添加代理配置。如果启用了注册,这将开始在代理上注册。