SDK 介绍

iotcloud_sdk_x.x.x

├── arm64-v8a

│ └── libcloudcore.so 动态链接库

├── armeabi

│ └── libcloudcore.so 动态链接库

├── armeabi-v7a

│ └── libcloudcore.so 动态链接库

├── iot_cloud_sdk_x.x.x.jar SDK核心库文件

├── mips

│ └── libcloudcore.so 动态链接库

├── mips64

│ └── libcloudcore.so 动态链接库

├── x86

│ └── libcloudcore.so 动态链接库

└── x86_64

​ └── libcloudcore.so 动态链接库

SDK初始化

1、在官网左上角点击授权管理

2、添加应用即可获得AppID和AppToken

推荐在Application中进行初始化,注意只需要在主进程初始化一次即可

@Override

public void onCreate() {

super.onCreate\(\);

// 判断是主进程

if (getApplicationInfo().packageName

.equals(getCurProcessName(getApplicationContext()))) {

/__

\* 初始化SDK

\*/

IotCloudSDK.init\(this, AppId, AppToken\);

// 设置需要登录时的状态回调,用来处理页面跳转,比如跳转到登录页面

IotCloudSDK.setNeedLoginListener

(new INeedLoginListener() {

@Override

public void onNeedLogin\(Context context\) {

try {

Intent intent = new Intent(context,

SetAppIdActivity.class);

intent.addFlags\(Intent.FLAG\_ACTIVITY\_CLEAR\_TASK\);

intent.addFlags\(Intent.FLAG\_ACTIVITY\_NEW\_TASK\);

startActivity\(intent\);

} catch \(Exception e\) {

Intent intent = new Intent\(context, SetAppIdActivity.class\);

intent.addFlags\(Intent.FLAG\_ACTIVITY\_NEW\_TASK\);

startActivity\(intent\);

}

}

}\);

DeviceController.bindGlobalMessage\(this\);

// 返回当前SDK的长连接状态

IotCloudSDK.setConnectionStatusListener\(new IConnectionStatusListener\(\) {

@Override

public void onConnectionStatus\(int i\) {

LogUtils.e\("MQTT当前状态: " + i\);

}

}\);

}

}

public static String getCurProcessName(Context context) {

int pid = android.os.Process.myPid\(\);

ActivityManager activityManager = \(ActivityManager\) context

.getSystemService\(Context.ACTIVITY\_SERVICE\);

for \(ActivityManager.RunningAppProcessInfo appProcess : activityManager

.getRunningAppProcesses\(\)\) {

if \(appProcess.pid == pid\) {

return appProcess.processName;

}

}

return null;

}

@Override

public void onMessage(CloudMessage cloudMessage) {

if \(cloudMessage.getErrorMessage\(\).getCode\(\) == CommonError.MQTT\_MESSAGE\_SUCCESS\) {

// success

switch \(cloudMessage.getType\(\)\) {

case CloudMessageType.TYPE\_OTA\_REV: // 有设备需要手动OTA升级

break;

case CloudMessageType.TYPE\_SHARE\_REV: // 有分享消息,请到分享消息列表查看

int shareType = CloudShareMessageType.getShareType\(cloudMessage\);

if \(shareType == CloudShareMessageType.TYPE\_DEVICE\) {

// 设备分享消息

LogUtils.e\("设备分享消息"\);

} else if \(shareType == CloudShareMessageType.TYPE\_FAMILY\) {

// 家庭分享消息

LogUtils.e\\("家庭分享消息"\\);

}

\);

break;

}

} else {

// 错误消息

LogUtils.e\(cloudMessage.getErrorMessage\(\)\);

}

}

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

results matching ""

    No results matching ""