Android Standardization Demo Documentation - Imou Open Platform
1. Android standardization Demo documentation
The Android standard demo implements core audio and video features of the Imou Cloud Open Platform using OpenSDK components.
It is recommended that developers read the Demo source code as a reference or transplant it to their own project, which is helpful for quick integration.
Android standardization Demo download
Special attention:
Since Demo does not have a background saas service, Demo directly requests an open platform interface on the client side to obtain data and other operations.
Use your backend SaaS service to call Imou Open API where possible, then return data to the client app (cloud-to-cloud integration).
Calling Open API requires
appIdandappSecret. Embedding them in the client APK risks credential leakage if the app is reverse-engineered.
The process is as follows:

2. Function description
Administrator mode login-get accessToken as a required parameter for each Api interface and SDK method
Get the device list-get the devices bound to the open platform and the easy4ip App respectively
Device details-device unbinding, arming settings, device upgrades, network configuration, etc.
Real-time preview-video playback, voice intercom, screenshots, local recording, etc.
Video playback-video download, cloud video/device video playback, double-speed playback, etc.
Device Add function has been encapsulated into a separate module component for direct use by customers

3. Technical terms
| Technical terms | Description |
|---|---|
| Administrator mode | Use the AppId and AppSecret registered on the open platform to exchange for accessToken, similar to the concept of account login |
| Get device list | Request device list related interfaces through the developer account, and get the devices under the developer account from the Imou Cloud Open Platform List of lists. |
| Real-time preview, local recording/capture | Real-time preview refers to the process of obtaining the real-time code stream of the device on the client (such as mobile phone), and decoding & displaying; local recording refers to the process of The behavior of storing the preview stream as a local video file supports recording in MP4 format; local capture refers to the behavior of storing the current preview screen as a local picture during the real-time preview process, and the picture is in JPG format. |
| Device video playback | Obtain the video file stream stored in the SD card in the device on the client, and perform the process of decoding & displaying. |
| Voice Intercom | The process of an intercom call between the client and the device. Currently, two-way voice intercom is supported. |
| Cloud video playback | The client obtains the video stored in the cloud by the device, and performs the process of decoding & displaying. |
| Motion detection switch | Whether to generate alarm messages and video recording when the device detects movement. |
| PTZ | That is, through the terminal (such as App) to control the operating equipment. |
| OpenApi | The interface between the client and the easy4ip platform, Restful Api style. |
4. Project structure description
The directory structure after downloading the demo source code from the official website and decompressing it is shown in the figure below:
- DeviceAddModule folder is a device add module
- DeviceDetailModule folder is the device detail module
MediaModule folder is a media module
MessageModule folder is a message module
mobilecommon folder is a public module
PlayBackModule folder is video recording module
thrid zxing folder is the dependent module of the device adding module, which is mainly used for scanning the code (reading the QR code on the device and parsing it) when adding the device
usermodule folder is a user module
app folder is the demo source code, which depends on DeviceAddModule

5. Simulate login with administrator account
According to the different scenarios in which developers develop applications, the capabilities of the easy4ip open platform cloud video used will also vary.
Before obtaining the administrator device list and performing device operations, you need to obtain the accessToken (administrator token). We call the process of obtaining the accessToken as the administrator account simulation login process. After obtaining the administrator token, directly enter the device list interface.
The source code of Android Demo has helped developers to implement the code of the "accessToken" interface. For details, please see com.mm.android.mobilecommon.openapi.TokenHelper.java. The getToken method under the class.
6. Get device list
Demo will display the device list bound by the open platform and the easy4ip App under this account. For details, please refer to the example code: deviceList method in com.lechange.demo.ui.DeviceListActivity.java.
The process is shown in the figure below:

7. Real-time preview page
The real-time preview page mainly displays the real-time video stream pulled from the device. It supports two playback styles of horizontal and vertical screens. It also includes functions such as intercom, pan-tilt, and capture/recording. For details, please refer to the DeviceOnlineMediaPlayActivityNew.java file in the Demo code.
The process is shown in the figure below:

7.1 Real-time preview and voice intercom
Both of these functions use the methods in the SDK, and some of the SDK interface parameters involved are explained as follows:
Equipment Number: You can get the corresponding equipment number when you get the detailed list of equipment
Channel number: You can get the corresponding channel number when you get the detailed device list
Play code: You can get the corresponding play code when you get the detailed device list
Stream Type: The default is HD Stream 0: HD Stream 1: SD Stream
7.2 Gimbal
Call the OpenApi interface to implement the App control device. For the specific code, please refer to the controlMovePTZ method of DeviceInfoOpenApiManager.java
7.3 Video List
After you have purchased the cloud storage package, you can view cloud recordings. For the OpenApi request involved, please refer to the getCloudRecords method of DeviceInfoOpenApiManager.java
After the device has a TF card, you can view the device video. For the OpenApi request involved, please refer to the queryLocalRecords method of DeviceInfoOpenApiManager.java
7.4 Video Cover
Demo will save the last frame before exiting the real-time preview page, and save it in the local database and SD card as the default picture for the device list page and preview page. For specific code, please refer to DeviceLocalCacheManager.java and DeviceLocalCacheDatabase.java
8. Device details
8.1 Device upgrade
When the device program is updated, the device can be upgraded through the OpenApi interface. For the code, please refer to the upgradeDevice method of DeviceInfoOpenApiManager.java
8.2 Device rename
Please refer to the modifyDeviceName method of DeviceInfoOpenApiManager.java for the code
8.3 Device Arming Settings
For the code, please refer to the modifyDeviceAlarmStatus method of DeviceInfoOpenApiManager.java
8.4 Device network configuration
When the device is online, the wifi network currently connected to the device and the wifi information around the device can be queried through OpenApi, and at the same time, the wifi network can be switched to other devices.
Please refer to the code involved in requesting OpenApi:
CurrentDeviceWifi method of DeviceAddOpenApiManager.java
WifiAround method of DeviceAddOpenApiManager.java
ControlDeviceWifi method of DeviceAddOpenApiManager.java
8.5 Unbind Device
For the code, please refer to the unBindDevice method of DeviceInfoOpenApiManager.java
8.6 Local storage
For the code, please refer to the getDeviceStoreInfo, deviceSdcardStatus method of DeviceInfoOpenApiManager.java
8.7 Cloud storage
For the code, please refer to the setAllStorageStrategy method of DeviceInfoOpenApiManager.java
9. Video playback
The video playback page displays the playback function of a segment in the video list, which mainly includes cloud video playback/pause, download, double-speed playback, snapshot, and recording functions, and device video playback/pause, snapshot, and recording functions. The functions involved all call methods in the SDK. For details, please refer to the DeviceRecordPlayActivityNew.java file.
The main process is as follows:

10. Add components to the device
10.1 Use process
Import DeviceAddModule into your own project, the steps are as follows:
- In the Android studio menu bar, select File -> New -> Import Module

- Select the path where DeviceAddModule is located in the demo project, click finish to complete import


- In the build file in the app directory of your project, the sample code is as follows:
//High version Android Stduio
api project(':usermodule')
api project(':MediaModule')
api project(':PlaybackModule')
api project(':MessageModule')
api project(':DeviceDetailmodule')
//Or lower version Android Stduio
compile project(':usermodule')
compile project(':MediaModule')
compile project(':PlaybackModule')
compile project(':MessageModule')
compile project(':DeviceDetailmodule')
Remarks: Some developers, after completing the above integration steps, the compiled project may report Manifest merger failed with multiple errors, see logs. Add tools:replace="android:allowBackup,android:label,android:supportsRtl" under the application node in AndroidManifest.xml.
- If the developer sets targetSdkVersion >=29 in the build.gradle file, you need to add android:requestLegacyExternalStorage="true" under the application tag node in the AndroidManifest.xml manifest file, Apply for special storage permissions.
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:requestLegacyExternalStorage="true"
tools:replace="android:allowBackup,android:label,android:supportsRtl"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
- The current device addition module is given to the developer in the form of source code. After the developer adds the module to his project after integrating the device, he can add some jars involved in the obfuscated file if he needs to obfuscate the related code of the device. Confusion of packages:
#gson
-keepattributes Signature
-dontwarn com.google.gson.**
-keep class sun.misc.Unsafe {*;}
-keep class com.google.gson.**{*;}
#eventbus
-keep class org.greenrobot.eventbus.**{*;}
-keepclassmembers class **{
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode {*;}
#zxing.jar
-dontwarn com.google.zxing.**
-keep class com.google.zxing.**{*;}
#lechangeSDK.jar
-dontwarn com.lechange.**
-keep class com.lechange.**{*;}
-dontwarn com.company.**
-keep class com.company.**{*;}
#pulltorefreshlib.jar
-dontwarn com.lechange.pulltorefreshlistview.**
-keep class com.lechange.pulltorefreshlistview.**{*;}
#DHScanner-1.0.7.aar
-dontwarn com.mm.android.**
-keep class com.mm.android.**{*;}
#imageload4dh.jar
-dontwarn com.nostra13.universalimageloader.**
-keep class com.nostra13.universalimageloader.**{*;}
10.2 Calling the sample code
/**
* The first step: initialize the device to add a module
*
* 1: When using the device to add a module, you must first call this method to complete the initialization. This initialization will include the setHost() method in the LCOpenSDK_Api class, so there is no need to call setHost() again
* 2: This method will throw an exception. If the initialization fails (such as failure to obtain the token, etc.), the specific Throwable will be returned in the exception
*/
try {
CommonParam commonParam = new CommonParam();
//(Required) The domain name (including port) of the incoming open platform, generally used in China: https://openapi-[DataCenter].easy4ip.com:443, and generally used overseas: https://openapi-[DataCenter].easy4ip.com:443
commonParam.setEnvirment("https://openapi-[DataCenter].easy4ip.com:443");
//(Required) Android Application object
commonParam.setContext(EnvGuideActivity.this.getApplication());
//(Required) Application Id (obtained by registration on easy4ip Open Platform)
commonParam.setAppId("Please replace with your own appId");
//(Required) Application Id (obtained by registration on easy4ip Open Platform)
commonParam.setAppSecret("Please replace with your own appSecret");
//(Optional) The unique id of the user, the default appId
commonParam.setUserId("");
//Start initialization
LCDeviceEngine.newInstance().init(commonParam);
} catch (Throwable e) {
}
/**
* Step 2: Open the device adding process
*
* 1: This method will throw an exception (such as uninitialized, etc.)
* 2: This method needs to be called after the init initialization is successful
*/
try {
LCDeviceEngine.newInstance().addDevice(this);
} catch (Exception e) {
}
10.3 Matters needing attention
The AndroidManifest.xml file of the device addition module has enabled all permissions required by the easy4ip SDK by default. Developers do not need to enable permissions after adding the module to the integrated device. For specific permissions, please refer to the AndroidManifest.xml file in the device addition module.
The Init method in the LCDeviceEngine class in the device addition module contains the call of LCOpenSDK_Api.setHost, so if the device addition module is used in the developer's project, there is no need to call the setHost interface again.
The source code provided by the device addition module currently does not support AndroidX, so if the developer's project uses AndroidX, the device addition module can be converted to AndroidX by the following methods:
Method 1: Use AndroidStudio to convert Android to AndroidX, the specific operation can be done by Baidu;
Method 2: Package the device addition module as aar, and then introduce it into your own project.
