SDK 介绍

SDK名称

iot_cloud_sdk_x.x.x.jar,包含cacert.pem证书和各个接口,各个平台so库文件。

配置

build.gradle依赖

dependencies {

compile ‘org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0’

compile ‘com.google.code.gson:gson:2.8.2’

}

AndroidManifest.xml权限配置

<!—存储卡

<uses-permission android:name=”android.permission.READ_EXTERNAL_STORAGE” />

<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” />

<uses-permission android:name=”android.permission.MOUNT_UNMOUNT_FILESYSTEMS” />

<!—联网

<uses-permission android:name=”android.permission.INTERNET” />

<uses-permission android:name=”android.permission.CHANGE_NETWORK_STATE” />

<uses-permission android:name=”android.permission.CHANGE_WIFI_STATE” />

<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_MULTICAST_STATE” />

<uses-permission android:name=”android.permission.WAKE_LOCK” />

<permission

android:name=”应用包名.permission.IOTCLOUD_MESSAGE”

android:protectionLevel=”signature” />

<uses-permission android:name=”应用包名.permission.IOTCLOUD_MESSAGE” />

<!—Application中配置à

<service

android:enabled=”true”

android:name=”com.iot.cloud.sdk.api.MQTTService”

android:exported=”false”

android:permission=”应用包名.permission.IOTCLOUD_MESSAGE” />

消息接收的配置

消息接受采用广播的形式,用户使用静态或者动态的形式注册广播接收者。

例子:

<receiver

android:enabled=”true”

android:exported=”false”

android:name=”com.xxx.xxx.你的广播接收者类名”

android:permission=”应用包名.permission.IOTCLOUD_MESSAGE”>

<intent-filter>

<action android:name=”com.iot.cloud.sdk.intent.MESSAGE_RECEIVED”/>

</intent-filter>

</receiver>

动态注册原理相同,action和permission与静态广播中的一致即可。

例子:

public class MqttBroadcast extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

DeviceController.onReceive(intent);

}

}

Copyright & copy qinglianyun all right reserved,powered by Gitbook该文件修订时间: 2021-04-22 18:53:48

results matching ""

    No results matching ""