Android OpenSDK Docking Document and Integration Guide - Imou Open Platform
Android OpenSDK docking document
Take Demo project construction as an example (IDE is AndroidStudio, AS) to introduce developers to the OpenSDK docking process.
Android OpenSDK resource download
1. OpenSDK installation
Download and unzip the Android OpenSDK compressed package
Copy the libs/LCOpenSDK.aar file to the directory corresponding to your own project.
The structure of the AS project after the addition is as follows:

2. Project Configuration
2.1 Configure AndroidManifest
Related permissions need to be set in AndroidManifest.xml:
<!-- Basic permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- Required permissions for distribution network -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Bluetooth pairing (Android 12+); see [Mobile privacy](/book/06-sdk/08.privacy.html) -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<!-- Intercom required permissions -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
Note: Please be sure to set the relevant permissions, otherwise it may cause some failures: not opening the voice permission will cause the intercom to fail; not opening the read and write permissions will cause the video download to fail, the wireless distribution network has no sound and the network configuration fails, etc. Bluetooth provisioning/pairing requires
BLUETOOTH_*(see Mobile privacy).
2.2 Configure build.gradle
In the build.gradle file of the app of the AS project, you can select a compatible architecture according to your needs:
android {
…
defaultConfig {
…
ndk{
abiFilters "armeabi","arm64-v8a"
}
}
}
3. Device add function
Adding a device refers to the process of first configuring the network for the device, and then binding the device to the current account.
The SDK currently supports two network distribution methods: wireless distribution network and Soft AP network distribution (wired network does not need to be configured).
Because the wireless addition process is more complicated, in order to facilitate developers to realize the function of adding devices flexibly and freely, we provide two solutions for adding devices: one is to directly call the interface provided by the SDK, and the developer can implement the device addition function by himself; the other is to use Add modules to the devices encapsulated in the demo to realize quick docking.
Remarks:
Add instructions for unbound devices:
Before configuring the network, you need to clarify the type of network distribution supported by the current device, and then select the corresponding network distribution method.
For wireless devices, you need to use the wireless pairing function to pass the device's Wifi password, which can be added after the device is online.
For devices that support soft AP method addition (the device has a hotspot), the soft AP pairing function needs to be used.
For wired cables, you can directly check the status after connecting to the internet cable to add it online (there is no network configuration process, but the network cable must be able to connect to the external network).
The following describes the docking process of the two types of solutions:
3.1 Call SDK interface to add wirelessly
3.1.1 SmartConfig add
Steps to add device:
Developers can obtain information such as device S/N by scanning the label at the bottom of the device or manually entering it.
Call the unBindDeviceInfo API to query the network mode and binding status supported by the device.
Check whether the device is binding.
Judge whether the network mode supported by the current device is smartConfig.
Call deviceAddingProcessGuideInfoGet to get the device addition guide page and copywriting prompt information (this step is not necessary).
Start the wireless network and search the device initialization information in the LAN.
Stop the network after searching the device and stop searching the device.
Initialize the device (if the device has no security code, it needs to be initialized through SDK).
Check whether the device is online and the current capability set.
Bind device.

3.1.2 SoftAp add
Steps to add device:
Developers can obtain information such as device S/N by scanning the label at the bottom of the device or manually entering it.
Call the unBindDeviceInfo API to query the network mode and binding status supported by the device.
Check whether the device is binding.
Judge whether the network mode supported by the current device is SoftAP.
Call deviceAddingProcessGuideInfoGet to get the device addition guide page and copywriting prompt information (this step is not necessary).
Connect device hotspot
LAN searches for device initialization information: if the device information is searched, it can be bound directly
Start SoftAP distribution network
Check whether the device is online and the current capability set.
Bind device.

3.2 Integrate LCDeviceAddModule
Steps to add equipment:
Import the device to add components, refer to Android standardization Demo documentation
Add controls to trigger device addition in the layout file
<TextView
android:id="@+id/tv_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
- Initialize device add module
try {
//Initialization parameters
CommonParam commonParam = new CommonParam();
commonParam.setEnvirment("https://openapi-[DataCenter].easy4ip.com:443");
commonParam.setContext(MainActivity.this.getApplication());
commonParam.setAppId("…");//Developer's own appid
commonParam.setAppSecret("…");//Developer's own appsecret
//Initialize add module
LCDeviceEngine.newInstance().init(commonParam);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
findViewById(R.id.tv_add).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
//Call device to add interface
LCDeviceEngine.newInstance().addDevice(MainActivity.this);
} catch (Exception e) {
e.printStackTrace();
}
}
});
4. OpenSDK initialization
LCOpenSDK_Api is an encapsulation class for rest interaction between the SDK and the open platform. It should be the first interface to be called, and initialize and set parameters before calling other interfaces.
The initialization process is as follows:

Sample code:
// init LCOpenSDK_Api
String token = ""; // Developer access token
String host = "openapi-[Data Center].easy4ip.com:443";
InitParams initParams = new InitParams(this, host, token);
try {
int iRet = LCOpenSDK_Api.initOpenApi(initParams);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
Note: Obtain an access token before init: Administrator accessToken or Sub-account accessToken. Replace
[DataCenter]inhostwith your data-center id (same as Open API base URL).
5. Set opensdk log level
Call
LCOpenSDK_Utils.enableLogPrint()to enable or disable SDK log outputCall
LCOpenSDK_Utils.setLogLevel()with0fatal,1error,2warning,3info, or4debug
Note:you can adjust the SDK log level to complete problem reproduction and log capture, which is convenient for subsequent problem location and analysis.
6. Play function
The playback types supported by the SDK mainly include: real-time preview, device video playback, and cloud video playback. Before using the SDK playback function, you need to create a playback parent window in the layout file:
<!-- Play window container -->
<FrameLayout
android:id="@+id/live_window"
android:layout_width="match_parent"
android:layout_height="200dp">
<!-- Render content -->
<FrameLayout
android:id="@+id/live_window_content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
Note: The class that completes the playback function in the SDK is implemented by inheriting FrameLayout, so a parent window container is required.
Initialize the parent window to play and calculate the height of the rendered content FrameLayout:
//Initialize the layout
FrameLayout fr_window = findViewById(R.id.live_window);
FrameLayout getFr_window_content = findViewById(R.id.live_window_content);
//Calculate the height of fr_window in a ratio of 9:16
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(fr_window.getLayoutParams());
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
layoutParams.width =metrics.widthPixels;//screen width
layoutParams.height = metrics.heightPixels*9/16;
layoutParams.setMargins(0, 0, 0, 0);
fr_window.setLayoutParams(layoutParams);
6.1 Real-time preview
The main steps of real-time preview are:
Create layout and initialize (refer to 2.4)
Initialize the play class LCOpenSDK_PlayRealWindow
Add event listener and tidy up listener to LCOpenSDK_ PlayRealWindow class
Get playback parameters (Developer Device management)
Start/stop playback
Release resources
The preview process is:

Sample code:
//Initialize playwindow
LCOpenSDK_PlayRealWindow playWindow= new LCOpenSDK_PlayRealWindow();
playWindow.initPlayWindow(this, (ViewGroup) findViewById(R.id.live_window_content), 0, false);
//The developer implements event monitoring and sets the monitoring to playWindow
LCOpenSDK_EventListener listener = new LCOpenSDK_EventListener(){...}//Developer implements event listener callback
playWindow.setWindowListener(listener);
//Turn on tidy up monitoring
playWindow.openTouchListener();
/**
* Start preview
* 1. Prepare to preview the parameters
* 2. Open preview
* 3. Process the preview result in the LCOpenSDK_EventListener callback
* 4. Stop preview
* 5. Release resources
*/
LCOpenSDK_ParamReal paramReal = new LCOpenSDK_ParamReal()
playWindow.playRtspReal(paramReal);
playWindow.stopRtspReal(true);
playWindow.uninitPlayWindow();
6.2 Device video playback
The main steps of device video playback are:
Create layout and initialize (refer to 2.4)
Initialize the play class LCOpenSDK_PlayBackWindow
Add event listener and tidy up listener to LCOpenSDK_PlayBackWindow class
Get playback parameters (Developer Local recording)
Start/stop playback
Release resources
The playback process is:

Sample code:
//Initialize playwindow
LCOpenSDK_PlayBackWindow playWindow= new LCOpenSDK_PlayBackWindow();
playWindow.initPlayWindow(this, (ViewGroup) findViewById(R.id.live_window_content), 0, true);
//The developer implements event monitoring and sets the monitoring to playWindow
LCOpenSDK_EventListener listener = new LCOpenSDK_EventListener(){...}//Developer implements event listener callback
playWindow.setWindowListener(listener);
//Turn on tidy up monitoring
playWindow.openTouchListener();
/**
* Start playback
* 1. Ready to playback parameters
* 2. Turn on playback
* 3. Process the playback result in the LCOpenSDK_EventListener callback
* 4. Stop playback
* 5. Release resources
*/
LCOpenSDK_ParamDeviceRecord paramDeviceRecord = new LCOpenSDK_ParamDeviceRecord(...);//Developers get it from the video list
playWindow.playRtspPlayback(paramDeviceRecord);
playWindow.stopRtspPlayback(true);
playWindow.uninitPlayWindow();
6.3 Cloud video playback
The main steps of cloud video playback are:
Create layout and initialize (refer to 2.4)
Initialize the play class LCOpenSDK_PlayBackWindow
Add event listener and tidy up listener to LCOpenSDK_PlayBackWindow class
Get playback parameters (Developer Get device cloud recording information)
Start/stop playback
Release resources
The cloud video playback process is:

Sample code:
//Initialize playwindow
LCOpenSDK_PlayBackWindow playWindow = new LCOpenSDK_PlayBackWindow();
playWindow.initPlayWindow(this, (ViewGroup) findViewById(R.id.live_window_content), 0, true);
//The developer implements event monitoring and sets the monitoring to playWindow
LCOpenSDK_EventListener listener = new LCOpenSDK_EventListener(){...}//Developer implements event listener callback
playWindow.setWindowListener(listener);
//Turn on tidy up monitoring
playWindow.openTouchListener();
/**
* Start playback
* 1. Ready to playback parameters
* 2. Turn on playback
* 3. Process the playback result in the LCOpenSDK_EventListener callback
* 4. Stop playback
* 5. Release resources
*/
LCOpenSDK_ParamCloudRecord paramCloudRecord = new LCOpenSDK_ParamCloudRecord(...)//The developer gets it from the cloud recording list
playWindow.playCloud(paramCloudRecord);
playWindow.stopCloud(true);
playWindow.uninitPlayWindow();
Remarks:
- The playback window monitor callback class is very important, and it is the direct callback interaction class between the upper layer and the bottom layer.
- For the LCOpenSDK_EventListener class, please refer to the OpenSDK interface documentation.
7. Voice intercom function
The current intercom of OpenSDK can only be intercom when the preview is successfully turned on. The main steps of the intercom function are as follows:
Get intercom parameters
Confirm talk capability (
AudioTalkorAudioTalkV1in the deviceabilitystring from Device query)Set up monitoring for intercom
Start intercom
Stop intercom
The intercom process is:

Sample code:
//Turn off the preview sound
playWindow.stopAudio();
//Set up intercom monitoring
LCOpenSDK_Talk.setListener(new LCOpenSDK_TalkerListener());
//Prepare the intercom parameters (the developer obtains the device information currently being previewed)
LCOpenSDK_ParamTalk paramTalk = new LCOpenSDK_ParamTalk(...);
//Start intercom
LCOpenSDK_Talk.playTalk(paramTalk);
//Stop intercom
LCOpenSDK_Talk.stopTalk();
//Release the intercom monitor
LCOpenSDK_Talk.setListener(null);
//Turn on the preview sound
playWindow.playAudio();
8. Download function
The downloads supported by the SDK include device SD card video download and cloud video download. The following describes the flow of the two download functions.
8.1 Device video download
The main steps of device video downloading are:
Get device recording list
Initialize device video download parameters
Set up download monitoring
start download
Device video download process:

Sample code:
//Get device recording list (developer requests to get it)
// queryLocalRecords — see [Local record APIs](/book/05-api/90.old/device/record/local/summary.html)
//Set up download listener (the developer overrides the LCOpenSDK_DownloadListener class method)
LCOpenSDK_Download.setListener(new LCOpenSDK_DownloadListener());
//Start downloading (the developer is ready to download parameters)
LCOpenSDK_Download.startDownload(...);
8.2 Device cloud video download
The main steps of cloud video downloading are:
Get cloud recording list
Initialize cloud video download parameters
Set up download monitoring
start download
Cloud video download process:
Sample code:
//Get cloud recording list (developer requests to get it)
// queryCloudRecords — see [Cloud record APIs](/book/05-api/11.cloud/summary.html)
//Set up download listener (the developer overrides the LCOpenSDK_DownloadListener class method)
LCOpenSDK_Download.setListener(new LCOpenSDK_DownloadListener());
//Start downloading (the developer is ready to download parameters)
LCOpenSDK_Download.startDownload(...);
9. Device data decryption
Alarm thumbnails and recording cover images are stored encrypted by default. Call LCOpenSDK_Utils.decryptPic before display (keying follows device encryption mode and deviceId, similar to preview psk).
byte[] dataOut = null;
int ret = LCOpenSDK_Utils.decryptPic(encryptedBytes, deviceId, decryptKey, dataOut);
// When ret == 0, dataOut is JPEG/PNG bytes for your image view or Bitmap
See Alarm messages and record APIs for fields that return encrypted URLs or payloads.
