HDLLinphoneSDKDemoNew/HDLLinphoneSDK/libs/liblinphone-android-sdk.aarBinary files differ
HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/AndroidManifest.xml
@@ -13,6 +13,7 @@ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> <uses-feature android:name="android.hardware.camera" android:required="false" /> HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/HDLLinphoneKit.java
@@ -2,8 +2,6 @@ import android.content.Context; import android.content.Intent; import android.util.Log; import android.view.SurfaceView; import android.view.TextureView; import android.widget.Toast; @@ -12,17 +10,20 @@ import com.hdl.hdllinphonesdk.callback.OnLPOpenDoorCallBack; import com.hdl.hdllinphonesdk.core.callback.PhoneCallback; import com.hdl.hdllinphonesdk.core.callback.RegistrationCallback; import com.hdl.hdllinphonesdk.core.linphone.LinphoneUtils; import com.hdl.hdllinphonesdk.core.service.HDLLinphoneService; import com.hdl.hdllinphonesdk.utils.HDLLog; import org.linphone.core.AccountCreator; import org.linphone.core.Address; import org.linphone.core.AudioDevice; import org.linphone.core.AuthInfo; import org.linphone.core.Call; import org.linphone.core.CallParams; import org.linphone.core.CallStats; import org.linphone.core.Core; import org.linphone.core.CoreException; import org.linphone.core.Factory; import org.linphone.core.ProxyConfig; import org.linphone.core.TransportType; import static java.lang.Thread.sleep; @@ -31,20 +32,22 @@ */ public class HDLLinphoneKit { public static final String KEY_TITLE_NAME = "lpTitleName"; public static final String HDLLinphoneKitNAME = "HDLLinphoneKit"; private volatile static HDLLinphoneKit instance; private Context viewContext; private ServiceWaitThread mServiceWaitThread; private String mUsername, mPassword, mServerIP; private TextureView mRenderingView, mPreviewView; // private TextureView mRenderingView, mPreviewView; private boolean isAutoJumpCallView;//是否自动跳转呼叫页面 private HDLLinphoneKit() { } /** * getInstance * @return HDLLinphoneKit */ public static synchronized HDLLinphoneKit getInstance() { if (instance == null) { synchronized (HDLLinphoneKit.class) { @@ -57,33 +60,53 @@ } /** * 获取 LinphoneCore * * @return Core */ public Core getCore() { if(!HDLLinphoneService.isReady()){ CheckIfNeedstartService(); return null; }else { return HDLLinphoneService.getCore(); } } /** * 初始化Linphone * @param context */ public void initLinphone(Context context) { viewContext = context.getApplicationContext(); if (!HDLLinphoneService.isReady()) { startService(context); addCallback(new RegistrationCallback() { @Override public void registrationOk() { super.registrationOk(); Log.e(HDLLinphoneKitNAME, "registrationOk: "); callBackRegistrationOk(viewContext); } @Override public void registrationFailed() { super.registrationFailed(); Log.e(HDLLinphoneKitNAME, "registrationFailed: "); // Toast.makeText(LoginActivity.this, "登录失败!", Toast.LENGTH_SHORT).show(); } }, null); CheckIfNeedstartService(); } else { } } /** * startService */ private synchronized void CheckIfNeedstartService(){ startService(viewContext); addCallback(new RegistrationCallback() { @Override public void registrationOk() { super.registrationOk(); HDLLog.e(HDLLinphoneKitNAME, "registrationOk: "); callBackRegistrationOk(viewContext); } @Override public void registrationFailed() { super.registrationFailed(); HDLLog.e(HDLLinphoneKitNAME, "registrationFailed: "); // Toast.makeText(LoginActivity.this, "登录失败!", Toast.LENGTH_SHORT).show(); } }, null); } /** @@ -94,9 +117,15 @@ @Override public void incomingCall(Call linphoneCall) { super.incomingCall(linphoneCall); if (linphoneCall != null) { String callUsername = linphoneCall.getRemoteAddress().getUsername(); HDLLog.I("来电号码:" + callUsername); // HDLLog.Log("来电号码DisplayName:" + linphoneCall.getRemoteAddress().getDisplayName()); if (mOnHDLLinphoneCallListener != null) { mOnHDLLinphoneCallListener.onIncomingCall(callUsername); } } String callUsername = linphoneCall.getRemoteAddress().getUsername(); HDLLog.E("来电号码:" + callUsername); if (isAutoJumpCallView) { //是否需要自动打开呼叫页面 gotoHDLLinphoneIntercomActivity(); @@ -137,38 +166,48 @@ } /** * showToast */ private void showToast(String text) { Toast.makeText(viewContext, text, Toast.LENGTH_SHORT).show(); } /** * 开启服务 * * @param context 上下文 */ public void startService(Context context) { if (!HDLLinphoneService.isReady()) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClass(context, HDLLinphoneService.class); context.startService(intent); try { 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); // } } } catch (Exception e) { e.printStackTrace(); } } // /** // * 设置 sip 账户信息 // * // * @param username sip 账户 // * @param password 密码 // * @param serverIP sip 服务器 // */ // public void setAccount(String username, String password, String serverIP) { // mUsername = username; // mPassword = password; // mServerIP = serverIP; // } /** * onResume */ public void onResume() { } /** * onPause */ public void onPause() { } /** * onDestroy */ public void onDestroy() { removePreviewWindow(); removeVideoWindow(); } /** * 设置 sip 账户信息 @@ -222,6 +261,7 @@ /** * 退出清空账号 * enableRegister false */ public void logout() { try { @@ -235,63 +275,29 @@ config.done(); } } core.clearAllAuthInfo(); core.clearProxyConfig(); core.clearAllAuthInfo();//清除所有认证信息。 // core.clearProxyConfig();//从配置中删除所有代理。注意:目前不能直接删所有代理,因为服务器上还是标记已注册 } } catch (Exception e) { e.printStackTrace(); } } /** * 呼叫指定号码 * * @param num 呼叫号码 * 清除配置表, 切换账号时会用到 */ public void callTo(String num, boolean isVideoCall) { LinphoneUtils.getInstance().callTo(num, isVideoCall); public void clearProxyConfig(){ Core core = HDLLinphoneService.getCore(); if (core != null) { core.clearAllAuthInfo();//清除所有认证信息。 core.clearProxyConfig();//从配置中删除所有代理。 } } /** * 接听来电 * ServiceWaitThread */ public void acceptCall() { LinphoneUtils.getInstance().acceptCall(); } // /** // * 接听来电 // */ // public void acceptCallWithVideo(boolean enableVideo) { // LinphoneUtils.getInstance().acceptCallWithVideo(enableVideo); // } /** * 挂断当前通话 */ public void hangUp() { LinphoneUtils.getInstance().hangUp(); } /** * 切换静音 * * @param isMicMuted 是否静音 */ public void toggleMicro(boolean isMicMuted) { LinphoneUtils.getInstance().toggleMicro(isMicMuted); } /** * 切换免提 * * @param isSpeakerEnabled 是否免提 */ public void toggleSpeaker(boolean isSpeakerEnabled) { LinphoneUtils.getInstance().toggleSpeaker(isSpeakerEnabled); } private class ServiceWaitThread extends Thread { private PhoneCallback mPhoneCallback; private RegistrationCallback mRegistrationCallback; @@ -325,83 +331,203 @@ if (mUsername == null || mPassword == null || mServerIP == null) { throw new RuntimeException("The sip account is not configured."); } LinphoneUtils.getInstance().registerUserAuth(mUsername, mPassword, mServerIP); registerUserAuth(mUsername, mPassword, mServerIP); } catch (CoreException e) { e.printStackTrace(); } } /** * 提交账号和密码注册到服务器 * * @param name * @param password * @param host * @throws CoreException */ public void registerUserAuth(String name, String password, String host) throws CoreException { Core mLinphoneCore = HDLLinphoneService.getCore(); if(mLinphoneCore == null) return; // public static boolean getVideoEnabled() { // CallParams remoteParams = HDLLinphoneService.getCore().getCurrentCall().getRemoteParams(); // return remoteParams != null && remoteParams.videoEnabled(); // } AuthInfo authInfo = Factory.instance().createAuthInfo(name, null, password, null, null, host); AccountCreator mAccountCreator = mLinphoneCore.createAccountCreator(null); mAccountCreator.setUsername(name); mAccountCreator.setDomain(host); mAccountCreator.setPassword(password); mAccountCreator.setTransport(TransportType.Udp); ProxyConfig prxCfg = mAccountCreator.createProxyConfig(); prxCfg.enableQualityReporting(false); prxCfg.setQualityReportingCollector(null); prxCfg.setQualityReportingInterval(0); prxCfg.enableRegister(true); mLinphoneCore.addProxyConfig(prxCfg);//添加代理配置。如果启用了注册,这将开始在代理上注册。 mLinphoneCore.addAuthInfo(authInfo);//添加认证信息到,该信息片段将在所有需要的SIP事务中使用身份验证 mLinphoneCore.setDefaultProxyConfig(prxCfg);//设置默认代理。 } /** * 设置 SurfaceView * 呼叫 */ public Call startSingleCallingTo(String userName, boolean isVideoCall) { Core mLinphoneCore = HDLLinphoneService.getCore(); if(mLinphoneCore == null) return null; Call call = null; Core core = HDLLinphoneService.getCore(); if(core != null) { Address addressToCall = core.interpretUrl(userName); CallParams params = core.createCallParams(null); if (isVideoCall) { params.enableVideo(true); params.enableLowBandwidth(false); } else { params.enableVideo(false); } if (addressToCall != null) { call = core.inviteAddressWithParams(addressToCall, params); } } return call; } /** * 呼叫指定号码 * * @param num 呼叫号码 */ public void callTo(String num, boolean isVideoCall) { if (!HDLLinphoneService.isReady() || !HDLLinphoneService.getCoreIsNotNull()) { return; } if (!num.equals("")) { startSingleCallingTo(num, isVideoCall); } } /** * 接听来电 */ public void acceptCall() { try { if(HDLLinphoneService.getCore() == null) return; Call currentCall = HDLLinphoneService.getCore().getCurrentCall(); CallParams params = HDLLinphoneService.getCore().createCallParams(currentCall); params.enableVideo(true); currentCall.acceptWithParams(params); } catch (Exception e) { e.printStackTrace(); } } /** * 接听来电 */ public void acceptCallWithVideo(boolean enableVideo) { try { if(HDLLinphoneService.getCore() == null) return; Call currentCall = HDLLinphoneService.getCore().getCurrentCall(); CallParams params = HDLLinphoneService.getCore().createCallParams(currentCall); params.enableVideo(enableVideo); currentCall.acceptWithParams(params); } catch (Exception e) { e.printStackTrace(); } } /** * 挂断电话 */ public void hangUp() { Core mLinphoneCore = HDLLinphoneService.getCore(); if(mLinphoneCore == null) return; Call currentCall = mLinphoneCore.getCurrentCall(); if (currentCall != null) { // mLinphoneCore.terminateCall(currentCall); mLinphoneCore.terminateAllCalls(); } else if (mLinphoneCore.isInConference()) { mLinphoneCore.terminateConference(); } else { mLinphoneCore.terminateAllCalls(); } } /** * 是否静音 * * @param isMicMuted */ public void toggleMicro(boolean isMicMuted) { Core mLinphoneCore = HDLLinphoneService.getCore(); if(mLinphoneCore == null) return; mLinphoneCore.enableMic(!isMicMuted); } /** * 是否外放 * * @param isSpeakerEnabled */ public void toggleSpeaker(boolean isSpeakerEnabled) { routeAudioToSpeakerHelper(isSpeakerEnabled); } /** * 设置外放设备 */ private void routeAudioToSpeakerHelper(boolean speakerOn) { org.linphone.core.tools.Log.w("[Audio Manager] Routing audio to " + (speakerOn ? "speaker" : "earpiece")); try { if(HDLLinphoneService.getCore() == null) return; if (HDLLinphoneService.getCore().getCallsNb() == 0) return; Call currentCall = HDLLinphoneService.getCore().getCurrentCall(); if (currentCall == null) currentCall = HDLLinphoneService.getCore().getCalls()[0]; if (currentCall == null) return; for (AudioDevice audioDevice : HDLLinphoneService.getCore().getAudioDevices()) { if (speakerOn && audioDevice.getType() == AudioDevice.Type.Speaker) { currentCall.setOutputAudioDevice(audioDevice); return; } else if (!speakerOn && audioDevice.getType() == AudioDevice.Type.Earpiece) { currentCall.setOutputAudioDevice(audioDevice); return; } } } catch (Exception e) { e.printStackTrace(); } } /** * 设置 TextureView * * @param renderingView 远程 TextureView * @param previewView 本地 TextureView */ public void setAndroidVideoWindow(final TextureView renderingView, final TextureView previewView) { mRenderingView = renderingView; mPreviewView = previewView; // mRenderingView = renderingView; // mPreviewView = previewView; setVideoWindow(renderingView); setPreviewWindow(previewView); } /** * onResume * 设置播放View * @param o */ public void onResume() { // if (mRenderingView != null) { // ((TextureView) mRenderingView).onResume(); // } // if (mAndroidVideoWindow != null) { // synchronized (mAndroidVideoWindow) { // LinphoneManager.getLc().setNativeVideoWindowId(mAndroidVideoWindow); // } // } } /** * onPause */ public void onPause() { // if (mAndroidVideoWindow != null) { // synchronized (mAndroidVideoWindow) { // LinphoneManager.getLc().setNativeVideoWindowId(null); // } // } // // if (mRenderingView != null) { // ((GLSurfaceView) mRenderingView).onPause(); // } } /** * onDestroy */ public void onDestroy() { mPreviewView = null; mRenderingView = null; } // private void fixZOrder(SurfaceView rendering, SurfaceView preview) { // rendering.setZOrderOnTop(false); // preview.setZOrderOnTop(true); // preview.setZOrderMediaOverlay(true); // Needed to be able to display control layout over // } private void setVideoWindow(Object o) { Core linphoneCore = HDLLinphoneService.getCore(); if (linphoneCore != null) { linphoneCore.setNativeVideoWindowId(o); } } /** * 移除播放View */ private void removeVideoWindow() { Core linphoneCore = HDLLinphoneService.getCore(); if (linphoneCore != null) { @@ -409,28 +535,25 @@ } } /** * 设置本机摄像头采集的View * @param o */ private void setPreviewWindow(Object o) { Core linphoneCore = HDLLinphoneService.getCore(); if (linphoneCore != null) { linphoneCore.setNativePreviewWindowId(o); } } /** * 移除视频采集View */ private void removePreviewWindow() { Core linphoneCore = HDLLinphoneService.getCore(); if (linphoneCore != null) { linphoneCore.setNativePreviewWindowId(null); } } // /** // * 获取 LinphoneCore // * // * @return LinphoneCore // */ // public Core getLC() { // return HDLLinphoneService.getCore(); // } /** * 获取当前通话状态 @@ -452,6 +575,11 @@ public boolean isAutoJumpCallView() { return isAutoJumpCallView; } /** * 设置是否自动跳转呼叫页面标志 * @param autoJumpCallView */ public void setAutoJumpCallView(boolean autoJumpCallView) { isAutoJumpCallView = autoJumpCallView; } @@ -491,12 +619,27 @@ */ private OnHDLLinphoneCallListener mOnHDLLinphoneCallListener; /** * 获取onHDLLinphoneCallListener * 接听、挂断、开锁等 Listener实现 * @return OnHDLLinphoneCallListener */ public OnHDLLinphoneCallListener getOnHDLLinphoneCallListener() { return mOnHDLLinphoneCallListener; } /** * 设置onHDLLinphoneCallListener * @param onHDLLinphoneCallListener */ public void setOnHDLLinphoneCallListener(OnHDLLinphoneCallListener onHDLLinphoneCallListener) { mOnHDLLinphoneCallListener = onHDLLinphoneCallListener; } /** * showToast */ private void showToast(String text) { Toast.makeText(viewContext, text, Toast.LENGTH_SHORT).show(); } } HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneIntercomActivity.java
@@ -26,6 +26,7 @@ import com.hdl.hdllinphonesdk.callback.OnLPOpenDoorCallBack; import com.hdl.hdllinphonesdk.R; import com.hdl.hdllinphonesdk.utils.HDLImageUtils; import com.hdl.hdllinphonesdk.utils.HDLLog; /** * Linphone接听页面 @@ -97,7 +98,7 @@ } HDLLinphoneKit.getInstance().onDestroy(); Log.i(TAG,"onDestroy"); HDLLog.i(TAG,"onDestroy"); } @@ -263,7 +264,7 @@ if (isAnswer) { //如果之前已经接听了,回调是挂断 callTime = getTimerCallTime(); Log.i("callTime","callTime"+callTime); HDLLog.i("callTime","callTime"+callTime); HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onHangUpAction(callTime); } else { //如果之前没接听了,回调是拒接 HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneMonitorActivity.java
@@ -25,6 +25,7 @@ import com.hdl.hdllinphonesdk.R; import com.hdl.hdllinphonesdk.callback.OnLPOpenDoorCallBack; import com.hdl.hdllinphonesdk.utils.HDLImageUtils; import com.hdl.hdllinphonesdk.utils.HDLLog; /** *监视页面 @@ -83,7 +84,7 @@ } HDLLinphoneKit.getInstance().onDestroy(); Log.i(TAG,"onDestroy"); HDLLog.i(TAG,"onDestroy"); } @@ -293,14 +294,15 @@ HDLLinphoneKit.getInstance().setAndroidVideoWindow(video_lp_rendering, video_lp_rendering2); } /** * 页面关闭广播监听 */ public class FinishVideoActivityReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { HDLLinphoneMonitorActivity.this.finish(); } } private HDLLinphoneMonitorActivity.FinishVideoActivityReceiver mReceiver; public static final String RECEIVE_FINISH_VIDEO_ACTIVITY = "receive_finish_video_activity"; HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/callback/OnHDLLinphoneCallListener.java
@@ -27,6 +27,9 @@ */ void onScreenshotSuccessfulAction(Bitmap image); /** * 来电中 */ void onIncomingCall(String username); } HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/core/callback/PhoneCallback.java
@@ -3,7 +3,7 @@ import org.linphone.core.Call; /** * 状态回调 * 通话状态回调 */ public abstract class PhoneCallback { HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/core/callback/RegistrationCallback.java
@@ -1,7 +1,7 @@ package com.hdl.hdllinphonesdk.core.callback; /** * RegistrationCallback * 注册状态回调 */ public abstract class RegistrationCallback { HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/core/linphone/KeepAliveHandler.java
@@ -6,7 +6,7 @@ import android.util.Log; import com.hdl.hdllinphonesdk.core.service.HDLLinphoneService; import com.hdl.hdllinphonesdk.utils.HDLLog; /** * KeepAliveHandler @@ -22,7 +22,7 @@ try { Thread.sleep(2000); } catch (InterruptedException e) { Log.e(TAG, "Cannot sleep for 2s"); HDLLog.e(TAG, "Cannot sleep for 2s"); } } } HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/core/linphone/LinphoneManager.java
File was deleted HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/core/linphone/LinphoneUtils.java
File was deleted HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/core/linphone/PhoneBean.java
File was deleted HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/core/service/HDLLinphoneService.java
@@ -1,6 +1,9 @@ package com.hdl.hdllinphonesdk.core.service; import android.app.AlarmManager; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.Context; @@ -11,14 +14,14 @@ import android.os.Handler; import android.os.IBinder; import android.os.SystemClock; import android.support.v4.app.NotificationCompat; import com.hdl.hdllinphonesdk.HDLLinphoneKit; import com.hdl.hdllinphonesdk.R; import com.hdl.hdllinphonesdk.core.callback.PhoneCallback; import com.hdl.hdllinphonesdk.core.callback.RegistrationCallback; import com.hdl.hdllinphonesdk.core.linphone.KeepAliveHandler; import com.hdl.hdllinphonesdk.core.linphone.LinphoneUtils; import com.hdl.hdllinphonesdk.utils.HDLLog; import org.linphone.core.Call; import org.linphone.core.Core; @@ -51,7 +54,7 @@ private PendingIntent mKeepAlivePendingIntent; private static PhoneCallback sPhoneCallback;//通话状态回调 private static RegistrationCallback sRegistrationCallback;//账号注册登录状态回调 private String mRingSoundFile,mPauseSoundFile = null; private String mRingSoundFile, mPauseSoundFile = null; private Handler mHandler; private Timer mTimer; @@ -73,6 +76,9 @@ } public static Core getCore() { if(sInstance == null){ return null; } return sInstance.mCore; } @@ -82,26 +88,35 @@ return null; } /** * 添加通话状态回调 * @param phoneCallback */ public static void addPhoneCallback(PhoneCallback phoneCallback) { sPhoneCallback = phoneCallback; } public static void removePhoneCallback() { if (sPhoneCallback != null) { sPhoneCallback = null; } } /** * 添加注册状态回调 * @param registrationCallback */ public static void addRegistrationCallback(RegistrationCallback registrationCallback) { sRegistrationCallback = registrationCallback; } public static void removeRegistrationCallback() { if (sRegistrationCallback != null) { sRegistrationCallback = null; } } /** * 移除所以Callback */ public void removeAllCallback() { removePhoneCallback(); removeRegistrationCallback(); @@ -110,16 +125,13 @@ @Override public void onCreate() { super.onCreate(); hdlStartForeground(); initLinphone(); Intent intent = new Intent(this, KeepAliveHandler.class); mKeepAlivePendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); ((AlarmManager) this.getSystemService(Context.ALARM_SERVICE)).setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 60000, 60000, mKeepAlivePendingIntent); } @Override public int onStartCommand(Intent intent, int flags, int startId) { @@ -162,7 +174,7 @@ @Override public void onDestroy() { removeAllCallback(); logout(); mCore.removeListener(mCoreListener); mTimer.cancel(); mCore.stop(); @@ -174,6 +186,7 @@ ((AlarmManager) this.getSystemService(Context.ALARM_SERVICE)).cancel(mKeepAlivePendingIntent); hdlStopForeground(); super.onDestroy(); } @@ -189,21 +202,18 @@ * 初始化Linphone */ private void initLinphone() { String basePath = getFilesDir().getAbsolutePath(); Factory.instance().setLogCollectionPath(basePath); Factory.instance().enableLogCollection(LogCollectionState.Enabled); Factory.instance().setDebugMode(false, getString(R.string.app_name)); // Dump some useful information about the device we're running on Log.i(START_LINPHONE_LOGS); dumpDeviceInformation(); dumpInstalledLinphoneInformation(); // HDLLog.I(START_LINPHONE_LOGS); // dumpDeviceInformation(); // dumpInstalledLinphoneInformation(); mHandler = new Handler(); // This will be our main Core listener, it will change activities depending on events initCoreListener(); copyAssetsFromPackage(basePath); // Create the Core and add our listener mCore = Factory.instance() .createCore(basePath + "/.linphonerc", basePath + "/linphonerc", this); @@ -212,11 +222,14 @@ configureCore(); } /** * 初始化CoreListener监听 */ private void initCoreListener() { mCoreListener = new CoreListenerStub() { @Override public void onCallStateChanged(Core core, Call linphoneCall, Call.State state, String message) { Log.e(START_LINPHONE_LOGS, "callState: " + state.toString()); HDLLog.e(START_LINPHONE_LOGS, "callState: " + state.toString()); currentCallState = state; if (sPhoneCallback != null) { if (state == Call.State.IncomingReceived) { @@ -237,20 +250,28 @@ @Override public void onRegistrationStateChanged(Core core, ProxyConfig proxyConfig, RegistrationState registrationState, String message) { String state = registrationState.toString(); Log.i(START_LINPHONE_LOGS, "registrationState: " + state); if (sRegistrationCallback != null) { HDLLog.i(START_LINPHONE_LOGS, "registrationState: " + state); if (state.equals(RegistrationState.None.toString())) { if (state.equals(RegistrationState.None.toString())) { if (sRegistrationCallback != null){ sRegistrationCallback.registrationNone(); } else if (state.equals(RegistrationState.Progress.toString())) { } } else if (state.equals(RegistrationState.Progress.toString())) { if (sRegistrationCallback != null){ sRegistrationCallback.registrationProgress(); } else if (state.equals(RegistrationState.Ok.toString())) { } } else if (state.equals(RegistrationState.Ok.toString())) { if (sRegistrationCallback != null) { sRegistrationCallback.registrationOk(); } else if (state.equals(RegistrationState.Cleared.toString())) { } } else if (state.equals(RegistrationState.Cleared.toString())) { removeProxyConfig(core, proxyConfig); if (sRegistrationCallback != null) { sRegistrationCallback.registrationCleared(); } else if (state.equals(RegistrationState.Failed.toString())) { } } else if (state.equals(RegistrationState.Failed.toString())) { if (sRegistrationCallback != null) { sRegistrationCallback.registrationFailed(); } } @@ -258,6 +279,26 @@ }; } /** * 收到注销成功后移除当前代理 * @param core * @param proxyConfig */ void removeProxyConfig(Core core, ProxyConfig proxyConfig) { try { HDLLog.i(START_LINPHONE_LOGS, "registrationState: 注销成功移除账号:" + proxyConfig.getIdentityAddress().getUsername()); //收到注销成功后移除当前代理 if (core != null) { core.removeProxyConfig(proxyConfig); } } catch (Exception e) { e.printStackTrace(); } } /** * mCore启动默认参数配置 */ private void configureCore() { // We will create a directory for user signed certificates if needed String basePath = getFilesDir().getAbsolutePath(); @@ -265,19 +306,18 @@ File f = new File(userCerts); if (!f.exists()) { if (!f.mkdir()) { Log.e(userCerts + " can't be created."); HDLLog.E(userCerts + " can't be created."); } } //设置UserAgent setUserAgent(); mCore.setUserCertificatesPath(userCerts); // mCore.setNativeRingingEnabled(true); // // mCore.setRemoteRingbackTone(mRingSoundFile); // mCore.setTone(ToneID.CallWaiting, mRingSoundFile); mCore.setRing(mRingSoundFile); // mCore.setPlayFile(mPauseSoundFile); // mCore.enableVideoCapture(false);//禁用手机摄像头视频采集 mCore.setNetworkReachable(true); @@ -288,7 +328,6 @@ mCore.enableEchoLimiter(true); //自适应码率控制 // boolean isAdaptiveRateControl = (boolean) SPUtils.get(mServiceContext, "adaptive_rate_control", true); mCore.enableAdaptiveRateControl(true); //audio 码率设置 mCore.getConfig().setInt("audio", "codec_bitrate_limit", 36); @@ -309,6 +348,9 @@ setCodecMime(); } /** * 设置编码格式 */ private void setCodecMime() { PayloadType[] ptList = mCore.getAudioPayloadTypes(); for (PayloadType pt : ptList) { @@ -330,6 +372,10 @@ mCore.setVideoPayloadTypes(ptVideoList); } /** * 设置是否启用铃声,目前发现设置无效待分析原因 * @param use */ public void enableDeviceRingtone(boolean use) { if (use) { mCore.setRing(null); @@ -338,6 +384,9 @@ } } /** * 设置UserAgent */ private void setUserAgent() { try { String versionName = this.getPackageManager().getPackageInfo(this.getPackageName(), @@ -351,6 +400,9 @@ } } /** * 打印相关信息 */ private void dumpDeviceInformation() { StringBuilder sb = new StringBuilder(); sb.append("DEVICE=").append(Build.DEVICE).append("\n"); @@ -362,9 +414,12 @@ sb.append(abi).append(", "); } sb.append("\n"); Log.i(sb.toString()); HDLLog.I(sb.toString()); } /** * 打印版本号信息 */ private void dumpInstalledLinphoneInformation() { PackageInfo info = null; try { @@ -374,11 +429,11 @@ } if (info != null) { Log.i( HDLLog.i( "[Service] Linphone version is ", info.versionName + " (" + info.versionCode + ")"); } else { Log.i("[Service] Linphone version is unknown"); HDLLog.I("[Service] Linphone version is unknown"); } } @@ -393,18 +448,10 @@ // The factory config is used to override any other setting, let's copy it each time copyFromPackage(R.raw.linphonerc_factory, "linphonerc"); mRingSoundFile = basePath + "/oldphone_mono.wav"; copyIfNotExist(R.raw.oldphone_mono, basePath + "/oldphone_mono.wav"); copyIfNotExist(R.raw.oldphone_mono, basePath + "/oldphone_mono.wav"); copyIfNotExist(R.raw.ringback, basePath + "/ringback.wav"); mPauseSoundFile = basePath + "/toy_mono.wav"; copyIfNotExist( R.raw.toy_mono, basePath + "/toy_mono.wav"); // LinphoneUtils.copyIfNotExist(mServiceContext, R.raw.ringback, mRingBackSoundFile); // LinphoneUtils.copyIfNotExist(mServiceContext, R.raw.toy_mono, mPauseSoundFile); // LinphoneUtils.copyIfNotExist(mServiceContext, R.raw.linphonerc_default, mLinphoneConfigFile); // LinphoneUtils.copyIfNotExist(mServiceContext, R.raw.linphonerc_factory, new File(mLinphoneFactoryConfigFile).getName()); // LinphoneUtils.copyIfNotExist(mServiceContext, R.raw.lpconfig, mLPConfigXsd); // LinphoneUtils.copyIfNotExist(mServiceContext, R.raw.rootca, mLinphoneRootCaFile); copyIfNotExist(R.raw.toy_mono, basePath + "/toy_mono.wav"); } catch (IOException ioe) { Log.e(ioe); @@ -412,6 +459,12 @@ } /** * copyIfNotExist * @param ressourceId * @param target * @throws IOException */ private void copyIfNotExist(int ressourceId, String target) throws IOException { File lFileToCopy = new File(target); if (!lFileToCopy.exists()) { @@ -419,6 +472,12 @@ } } /** * copyFromPackage * @param ressourceId * @param target * @throws IOException */ private void copyFromPackage(int ressourceId, String target) throws IOException { FileOutputStream lOutputStream = openFileOutput(target, 0); InputStream lInputStream = getResources().openRawResource(ressourceId); @@ -438,4 +497,44 @@ public Call.State getCurrentCallState() { return currentCallState; } /** * 注销所有账号 */ void logout() { try { if (mCore != null) { ProxyConfig[] configs = mCore.getProxyConfigList(); for (ProxyConfig config : configs) { if (config != null) { config.edit(); config.enableRegister(false); config.done(); } } HDLLog.E("注销所有账号"); // core.clearAllAuthInfo(); // core.clearProxyConfig(); } } catch (Exception e) { e.printStackTrace(); } } //通知ID public static final int NOTIFICATION_ID = 2; /** * 解决android8.0以上无法启动服务的问题 */ void hdlStartForeground() { } /** * stopForeground */ void hdlStopForeground() { // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // stopForeground(true); // } } } HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/utils/HDLImageUtils.java
@@ -81,15 +81,15 @@ } } catch (FileNotFoundException e) { Log.e("FileNotFoundException", "FileNotFoundException:" + e.getMessage().toString()); HDLLog.e("FileNotFoundException", "FileNotFoundException:" + e.getMessage().toString()); e.printStackTrace(); return false; } catch (IOException e) { Log.e("IOException", "IOException:" + e.getMessage().toString()); HDLLog.e("IOException", "IOException:" + e.getMessage().toString()); e.printStackTrace(); return false; } catch (Exception e) { Log.e("IOException", "IOException:" + e.getMessage().toString()); HDLLog.e("IOException", "IOException:" + e.getMessage().toString()); e.printStackTrace(); return false; HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/utils/HDLLog.java
@@ -4,11 +4,36 @@ import static com.hdl.hdllinphonesdk.HDLLinphoneKit.HDLLinphoneKitNAME; /** * 打印工具 */ public class HDLLog { private static boolean isOpen = true; public static void Log(String message){ if(isOpen){ /** * 是否启用打印 */ private static boolean enableLog = true; public static boolean isEnableLog() { return enableLog; } public static void setEnableLog(boolean enableLog) { HDLLog.enableLog = enableLog; } public static void I(String message){ if(enableLog){ Log.i(HDLLinphoneKitNAME, message); } } /** * 打印 * @param tag * @param msg */ public static void i(String tag, String msg){ if(enableLog){ Log.i(tag, msg); } } @@ -17,9 +42,18 @@ * @param message */ public static void E(String message){ if(isOpen){ if(enableLog){ Log.e(HDLLinphoneKitNAME, message); } } /** * Error 打印红色的错误信息 */ public static void e(String tag, String msg){ if(enableLog){ Log.e(tag, msg); } } } HDLLinphoneSDKDemoNew/app/libs/HDLLinphoneSDK-V1.0.1.aarBinary files differ
HDLLinphoneSDKDemoNew/app/src/main/java/com/example/hdllinphonesdkdemo/HDLUtils.java
@@ -23,7 +23,7 @@ //// mAudioPlayUtil.playAudioFile(AudioPlayUtil.CAPTURE_SOUND); // // final String strCaptureFile = context.getCapturesFolder() + "/" + System.currentTimeMillis() + ".jpg"; // Log.e(TAG, "captured picture file path is " + strCaptureFile); // HDLLog.e(TAG, "captured picture file path is " + strCaptureFile); // // if (TextUtils.isEmpty(strCaptureFile)) { // bmp.recycle(); HDLLinphoneSDKDemoNew/app/src/main/java/com/example/hdllinphonesdkdemo/MainActivity.java
@@ -13,8 +13,9 @@ import com.hdl.hdllinphonesdk.HDLLinphoneKit; import com.hdl.hdllinphonesdk.activity.HDLLinphoneMonitorActivity; import com.hdl.hdllinphonesdk.callback.OnHDLLinphoneCallListener; import com.hdl.hdllinphonesdk.core.EasyLinphone; //import com.hdl.hdllinphonesdk.core.EasyLinphone; import com.hdl.hdllinphonesdk.core.service.HDLLinphoneService; import com.hdl.hdllinphonesdk.utils.HDLLog; import org.linphone.core.Address; import org.linphone.core.Call; @@ -25,7 +26,7 @@ public class MainActivity extends Activity { private static final String TAG = "MainActivity"; private TextView mTextView,mTextView2,mTextView3; private TextView mTextView,mTextView2,mTextView3,mTextView4; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -34,7 +35,7 @@ mTextView = findViewById(R.id.tv_hello); mTextView2 = findViewById(R.id.mTextView2); mTextView3 = findViewById(R.id.mTextView3); mTextView4 = findViewById(R.id.mTextView4); mTextView.setOnClickListener(new View.OnClickListener() { @Override @@ -49,73 +50,95 @@ // HDLLinphoneKit.getInstance().setAccountAndLogin("61723164995710", "8ec02ce0", "sipproxy.ucpaas.com:25060"); // HDLLinphoneKit.getInstance().setAccountAndLogin("5555", "85521566", "116.62.26.215:5060"); // HDLLinphoneKit.getInstance().setAccountAndLogin("5555", "85521566", "test-gz.hdlcontrol.com:5060"); // HDLLinphoneKit.getInstance().setAccountAndLogin("6666", "85521566", "test-gz.hdlcontrol.com:5060"); HDLLinphoneKit.getInstance().setAccountAndLogin("7777", "85521566", "test-gz.hdlcontrol.com:5060"); // // HDLLinphoneKit.getInstance().setAccountAndLogin("8888", "85521566", "test-gz.hdlcontrol.com:5060"); // // HDLLinphoneKit.getInstance().setAccountAndLogin("4444", "85521566", "test-gz.hdlcontrol.com:5060"); } }); mTextView4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { HDLLinphoneKit.getInstance().setAccountAndLogin("5555", "85521566", "test-gz.hdlcontrol.com:5060"); } }); mTextView2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // HDLLinphoneKit.getInstance().callTo("61723164995779",true); // HDLcallTo("61723164995779",true); HDLcallTo("1427186301744910338",true); startActivity(HDLLinphoneMonitorActivity.class); logoutLog(); return; //// HDLLinphoneKit.getInstance().callTo("61723164995779",true); //// HDLcallTo("61723164995779",true); // HDLLinphoneKit.getInstance().callTo("1427186301744910338",true); // startActivity(HDLLinphoneMonitorActivity.class); } }); mTextView3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { logout(); HDLLinphoneKit.getInstance().logout(); } }); HDLLinphoneKit.getInstance().initLinphone(this); HDLLinphoneKit.getInstance().setAutoJumpCallView(true); setOnHDLLinphoneCallListener(); } /** * 退出清空账号 * enableRegister false */ public void logout() { try { Core core = HDLLinphoneService.getCore(); ProxyConfig[] configs = core.getProxyConfigList(); for (ProxyConfig config : configs) { if (config != null) { config.edit(); config.enableRegister(false); config.done(); if (core != null) { ProxyConfig[] configs = core.getProxyConfigList(); for (ProxyConfig config : configs) { if (config != null) { config.edit(); config.enableRegister(false); config.done(); } } core.clearAllAuthInfo();//清除所有认证信息。 // core.clearProxyConfig();//从配置中删除所有代理。 } // core.clearAllAuthInfo(); // core.clearProxyConfig(); } catch (Exception e) { e.printStackTrace(); } } public Call HDLcallTo(String userName, boolean isVideoCall) { Call call = null; Core core = HDLLinphoneService.getCore(); Address addressToCall = core.interpretUrl(userName); CallParams params = core.createCallParams(null); public void logoutLog() { try { Core core = HDLLinphoneService.getCore(); ProxyConfig[] configs = core.getProxyConfigList(); if(configs != null) { HDLLog.E("registrationState账户length" + configs.length); } if (isVideoCall) { params.enableVideo(true); params.enableLowBandwidth(false); } else { params.enableVideo(false); for (ProxyConfig config : configs) { HDLLog.E("registrationState账户"+config.getIdentityAddress().getUsername()); } } catch (Exception e) { e.printStackTrace(); } if (addressToCall != null) { call = core.inviteAddressWithParams(addressToCall, params); } return call; } boolean openSuccess; void setOnHDLLinphoneCallListener(){ @@ -156,7 +179,12 @@ public void onScreenshotSuccessfulAction(Bitmap image) { showToast("截图"); } }); @Override public void onIncomingCall(String s) { } }); } /** HDLLinphoneSDKDemoNew/app/src/main/res/layout/activity_main.xml
@@ -16,6 +16,16 @@ android:background="@android:color/holo_blue_light" android:text="登录" ></TextView> <TextView android:id="@+id/mTextView4" android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginTop="30dp" android:gravity="center" android:textColor="@android:color/white" android:background="@android:color/holo_blue_light" android:text="登录2" ></TextView> <TextView android:id="@+id/mTextView2" Shared.Droid.HDLLinphone/Shared.Droid.HDLLinphone/Jars/HDLLinphoneSDK-V1.0.1.aarBinary files differ
Shared.Droid.HDLLinphone/Shared.Droid.HDLLinphone/Properties/AssemblyInfo.cs
@@ -22,5 +22,5 @@ // Minor Version // Build Number // Revision [assembly: AssemblyVersion("1.0.1.2")] [assembly: AssemblyFileVersion("1.0.1.2")] [assembly: AssemblyVersion("1.0.1.3")] [assembly: AssemblyFileVersion("1.0.1.3")]