可視對講移動端SDK接口說明[Andriod]
1. 概述
1.1 編寫目的
本文是可視對講設備云對講和呼手機功能SDK接口說明。
1.2 名詞解釋
名詞 | 解釋 |
IoT | 物聯網 |
2. 介紹
通過集成對接SDK可以使門禁設備快速實現包括門禁機呼叫APP、APP調看門禁機、門禁機呼叫?機號等對講功能。本?旨在描述該SDK的集成?式及主要業務代碼。
限制條件:
編譯過程基于Android Studio 4.1.3
推薦使用GradlePlugin版本:4.1.2
推薦使用Gradle版本:6.5
推薦編譯SDK版本:30
最小支持SDK版本:21
3. SDK集成方法
3.1 導入所需文件
新建或打開已有工程,拷貝leephone.aar包到app/libs目錄下.
在app/build.gradle中添加aar包的引用,如圖所示。
...
android {
...
defaultConfig {
...
ndk.abiFilters "armeabi-v7a", "arm64-v8a"
}
}
...
repositories {
flatDir {
dirs 'libs' // aar dir
}
}
...
dependencies {
implementation(name:'leephone', ext:'aar')
...
}
3.2 在AndroidManifest.xml配置
?持的最低SDK版本為5.0:
<uses-sdk android:minSdkVersion="21" />
添加必要權限:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
3.3 代碼混淆配置
如果有做代碼混淆,請確保以下類不加入混淆
-keep class com.evideo.voip.** { *; }
-keep class com.lee.phone.** { *; }
4. 類及接口列表
4.1 類說明
類名 | 說明 |
EVVoipManager | 負責登錄SIP |
EVVoipAccount | SIP會話 |
EVVoipCall | 負責SIP通話 |
EVVideoView | 負責視頻顯示 |
EVVoipCallParams | 通話參數 |
4.2 接口說明
4.2.1流程關鍵接口
名稱 | 類名 | 方法名 |
初始化 | EVVoipManager | init(Context context, EVVoipManager.OnInitCallback callback) |
反初始化 | EVVoipManager | deInit(Context context) |
登錄SIP服務器 | EVVoipManager | EVVoipAccount login(String sipnum, String password, String displayName, String domain, int port) |
賬號狀態監聽 | EVVoipAccount | setAccountStateCallback(EVVoipAccount.AccountStateCallbackaccountStateCallback) |
來電監聽 | EVVoipManager | setIncomingCallback(EVVoipManager.IncomingCallbackincomingCallback) |
呼叫APP | EdgeBoxManager | callRoomID(String roomID, EVVoipCallParams params, EdgeBoxManager.OnCallRoomCallback callback) |
接聽 | EVVoipCall | accept(EVVideoView display) |
掛斷 | EVVoipCall | hangup() |
通話狀態監聽 | EVVoipCall | setCallStateCallback(EVVoipCall.CallStateCallbackcallStateCallback) |
5. 主要業務流程
5.1 初始化
在進?對講業務之前,需要先初始化該SDK,才能保證后續業務正常,后續的所有API調?都必須在SDK初始化成功的情況下執?。在應?的?命周期內,?般只進??次初始化。
public static void init(Context context, EVVoipManager.OnInitCallback callback)
// 初始化對講SDK
EVVoipManager.init(getApplicationContext(), new EVVoipManager.OnInitCallback() {
@Override
public void complete() {
// 對講SDK初始化成功
}
@Override
public void error(int code) {
// 對講SDK初始化失敗,錯誤代碼code
}
});
當不再使?對講業務時,可以調?deInit進?SDK反初始化。
// 反初始化對講SDK
EVVoipManager.deInit(getApplicationContext());
5.2 登入SIP服務器
在對講SDK初始化成功之后,需要進?SIP服務器登入,登入成功后可以得到EVVoipAccount對象。
EVVoipAccount EVVoipManager.login(String sipnum, String password, String displayName, String domain, int port)
為了能夠實時顯示賬號狀態,本SDK提供 AccountStateCallback 接?實時監聽當前賬號狀態。
mEVVoipAccount.setAccountStateCallback(new EVVoipAccount.AccountStateCallback() {
@Override
public void onState(EVVoipAccount.AccountState state) {
/* 獲取該賬號的狀態
* AccountState.ONLINE 在線
* AccountState.OFFLINE 離線
* AccountState.LOGINPROCESS 登入中
* AccountState.NONE ?賬號、未登入
*/
}
});
當不再使?對講業務,可以通過以下接?進?登出操作。
mEVVoipAccount.logoutEdgeBox();
5.3 呼叫監聽
為了使APP能夠響應設備通話請求,需要注冊?個來電回調監聽接?。
EVVoipManager.setIncomingCallback(new EVVoipManager.IncomingCallback() {
@Override
public void inComing(EVVoipCall evCall) {
// evCall表示當前來電的通話
}
});
為了能夠實時獲取當前的通話狀態,可以在EVVoipCall對象上設置?個通話狀態回調接?。
evCall.setCallStateCallback(new EVVoipCall.CallStateCallback() {
@Override
public void onState(CallState state, EndReason reason) {
// 參考?禁機呼叫APP示例
}
});
5.4 通話接聽
為了顯示設備的對講畫面,需要提供?個EVVideoView作為視頻容器,如果不提供則為?頻通話。
private EVVideoView eVideoView;
public int accept(EVVideoView display) throws EVVoipException;
// 初始化視頻繪制容器,EVVideoView是?個android.app.Fragment,?前只?持在xml布局?件中配置
mEVVideoView= (EVVideoView) getFragmentManager().findFragmentById(R.id.display_view);
try {
// 響應監控請求
evCall.accept(mEVVideoView);
} catch (EVVoipException e) {
e.printStackTrace();
}
5.5 通話掛斷
evVoipCall.setCallStateCallback(null);
try {
evVoipCall.hangup();
} catch (EVVoipException e) {
e.printStackTrace();
}
5.6 開門
通話中可以發送開門指令,在發送開門指令前先設置監聽器,通過監聽獲取開門指令執行結果。
EVVoipCall.unlock
evVoipCall.setUnlockCallback(new EVVoipCall.UnlockCallback() {
@Override
public void onSuccess() {
//開門成功
}
@Override
public void onFailure() {
//開門失敗
}
});
int ret = call.unlock();//開門
5.7 通話中呼叫監聽
EVVoipManager.setSwitchCallback
mOnSwitchCallback = new OnSwitchCallBack() {
@Override
public void onSwitch(EVVoipCall call) {
}
@Override
public void onResume(EVVoipCall call) {
}
@Override
public void onPause(EVVoipCall call) {
}
};
EVVoipManager.setSwitchCallback(mOnSwitchCallback);
5.8 對話視頻
evVoipCall.setOnRemoteVideoMuteListener(new OnRemoteVideoMuteListener() {
@Override
public void onRemoteVideoMuteAnswer(boolean mute) {
}
@Override
public void onRemoteVideoMuteOffer(boolean mute) {
}
});
5.9 開關視頻
evVoipCall.enableVideo
5.10 通話協議監聽
evVoipCall.setOnIceNatListener(new OnIceNatListener() {
@Override
public void OnAudioIceNatListener(int iceNet) {
case IceNatType.ICE_NAT_TYPE_HOST:
case IceNatType.ICE_NAT_TYPE_SRFLX:
case IceNatType.ICE_NAT_TYPE_PRFLX:
case IceNatType.ICE_NAT_TYPE_RELAY:
}
@Override
public void OnVideoIceNatListener(int iceNet) {
case IceNatType.ICE_NAT_TYPE_HOST:
case IceNatType.ICE_NAT_TYPE_SRFLX:
case IceNatType.ICE_NAT_TYPE_PRFLX:
case IceNatType.ICE_NAT_TYPE_RELAY:
}
});
evVoipCall.setOnMonitorListener(new OnMonitorListener() {
@Override
public void onMonitor() {
}
});
問題1:setOnMonitorListener接口作用
5.11 APP調看門禁機
呼叫對講設備
evVoipCall = VoipManager.getInstance().call(sipNum, evVoipCallParams);
設置通話狀態監聽
evVoipCall.setCallStateCallback(new CallStateCallback {
@Override
void onState(EVVoipCall.CallState var1, EVVoipCall.EndReason var2) {
}
});
設置呼叫失敗監聽
evVoipCall.setCallFailureCallback(new CallFailureCallback() {
@Override
public void onFailure() {
}
});
開啟麥克風(本地還是遠端)
evVoipCall.enableMicrophone(true); //true-關閉麥克風,false-開啟麥克風
開啟揚聲器
evVoipCall.enableSpeaker(true); //true-開啟揚聲器,false-關閉揚聲器
設置遠程視頻禁止監聽
evVoipCall.setOnRemoteVideoMuteListener(new OnRemoteVideoMuteListener() {
@Override
public void onRemoteVideoMuteAnswer(boolean mute) {
}
@Override
public void onRemoteVideoMuteOffer(boolean mute) {
}
});
6.調試方法
6.1日志抓取方法
6.2關鍵流程日志
6.3 啟動功能選擇Activity
adb shell am start com.lee.phone.demo/com.lee.phone.demo.ChooseActivity
6.4 強制關閉Demo
adb shell am force-stop com.lee.phone.demo
7.FAQ
7.1 Debug版本工作正常,Release工作啟動異常
2021-10-12 15:13:51.270 30733-30733/? A/DEBUG: Abort message: 'JNI DETECTED ERROR IN APPLICATION: mid == null
in call to CallStaticIntMethod
from void com.lee.phone.jni.LeeJni.leeInit(java.lang.String, java.lang.String, int, int, boolean, java.lang.String, java.lang.String, java.lang.String)'
2021-10-12 15:13:51.270 30733-30733/? A/DEBUG: x0 0000000000000000 x1 00000000000077db x2 0000000000000006 x3 0000007ffe2299b0
2021-10-12 15:13:51.270 30733-30733/? A/DEBUG: x4 fefeff71731e1f97 x5 fefeff71731e1f97 x6 fefeff71731e1f97 x7 7f7f7f7f7f7f7fff
2021-10-12 15:13:51.270 30733-30733/? A/DEBUG: x8 00000000000000f0 x9 156478bff1817c09 x10 0000000000000001 x11 0000000000000000
2021-10-12 15:13:51.270 30733-30733/? A/DEBUG: x12 fffffff0fffffbdf x13 ffffffffffffffff x14 0000000000000004 x15 ffffffffffffffff
2021-10-12 15:13:51.270 30733-30733/? A/DEBUG: x16 00000072780c3958 x17 000000727809fa70 x18 00000072795bc000 x19 00000000000077db
2021-10-12 15:13:51.270 30733-30733/? A/DEBUG: x20 00000000000077db x21 00000000ffffffff x22 00000071e1f50300 x23 00000071f2565945
2021-10-12 15:13:51.270 30733-30733/? A/DEBUG: x24 00000071f258754b x25 0000000000000001 x26 00000071f2bbc258 x27 0000007278bca9a0
2021-10-12 15:13:51.270 30733-30733/? A/DEBUG: x28 00000071f2a91338 x29 0000007ffe229a50
2021-10-12 15:13:51.270 30733-30733/? A/DEBUG: sp 0000007ffe229990 lr 000000727804f704 pc 000000727804f730
2021-10-12 15:13:51.650 30733-30733/? A/DEBUG: backtrace:
2021-10-12 15:13:51.650 30733-30733/? A/DEBUG: #00 pc 0000000000083730 /apex/com.android.runtime/lib64/bionic/libc.so (abort+160) (BuildId: 34c26ab262e93abd89e0bece8eedd768)
2021-10-12 15:13:51.650 30733-30733/? A/DEBUG: #01 pc 00000000004b9f68 /apex/com.android.runtime/lib64/libart.so (art::Runtime::Abort(char const*)+2280) (BuildId: 0e606603700990d6d4117e187ef17d14)
2021-10-12 15:13:51.650 30733-30733/? A/DEBUG: #02 pc 000000000000b458 /system/lib64/libbase.so (android::base::LogMessage::~LogMessage()+580) (BuildId: 34ca25523d4cef6dbfb222bd871ca0ed)
2021-10-12 15:13:51.650 30733-30733/? A/DEBUG: #03 pc 000000000037885c /apex/com.android.runtime/lib64/libart.so (art::JavaVMExt::JniAbort(char const*, char const*)+1584) (BuildId: 0e606603700990d6d4117e187ef17d14)
2021-10-12 15:13:51.650 30733-30733/? A/DEBUG: #04 pc 00000000003b605c /apex/com.android.runtime/lib64/libart.so (art::JNI::CallStaticIntMethod(_JNIEnv*, _jclass*, _jmethodID*, ...)+1464) (BuildId: 0e606603700990d6d4117e187ef17d14)
2021-10-12 15:13:51.650 30733-30733/? A/DEBUG: #05 pc 0000000000290da0 /data/app/com.mqsz.life-JDTtNTsP89Vr90VYRjaCTQ==/lib/arm64/libleephone.so (lee_phone_detect_cameras+132) (BuildId: d1fde14fc5dc0807eb669a513e0e682a303e5ada)
2021-10-12 15:13:51.650 30733-30733/? A/DEBUG: #06 pc 000000000045e644 /data/app/com.mqsz.life-JDTtNTsP89Vr90VYRjaCTQ==/lib/arm64/libleephone.so (lee_android_camera_init+120) (BuildId: d1fde14fc5dc0807eb669a513e0e682a303e5ada)
檢查Release模式下混淆配置是否正確,參考《3.3 代碼混淆配置》
7.2 leeMuteSpeaker和enableSpeaker區別
leeMuteSpeaker是SDK中把收到的音頻直接扔掉,不通過揚聲器播放這一步
enableSpeaker是android系統標準接口,切換揚聲器和聽筒