更新时间:2024-07-01 GMT+08:00
分享

删除设备

接口功能

当有新设备需要从网关移除时,通过调用设备删除接口将非直连设备从物联网平台删除。

接口描述

1
public static boolean rmvDevice(int cookie, String deviceId);

接口所属类

HubService

参数说明

字段

必选/可选

类型

描述

cookie

可选

int

Cookie有效值1-65535。

deviceId

必选

String

设备Id。

接口返回值

返回值

描述

true

成功。

false

失败。

此返回值是调用接口的同步返回结果,返回true只是说明接口调用成功,并不说明删除成功,设备删除成功需要收到TOPIC_RMVDEV_RSP广播。

返回结果

广播名称

广播参数

成员

描述

TOPIC_ RMVDEV_RSP

IotaMessage

(使用intent.getSerializableExtra(HubService.HUB_BROADCAST_IE_IOTAMSG)方法获取)

HUB_IE_RESULT

删除设备结果。

HUB_IE_COOKIE

Cookie有效值为1-65535。

HUB_IE_RESULT:

枚举项

枚举值

类型

描述

HUB_RESULT_SUCCESS

0

NA

添加/删除执行成功。

HUB_RESULT_DEVICE_EXIST

1

NA

设备已存在。

HUB_RESULT_DEVICE_NOTEXIST

2

NA

设备不存在。

HUB_RESULT_DEVICE_FAILED

255

NA

执行失败。

示例

开发者调用该接口进行设备删除 。

1
HubService.rmvDevice(122, deviceId);

结果处理:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
//java code 
BroadcastReceiver mRmvdeviceRsp;
mRmvdeviceRsp = new BroadcastReceiver() {
    @Override 
     public void onReceive(Context context, Intent intent) {
        //Do Something 
        IotaMessage iotaMsg = (IotaMessage)intent.getSerializableExtra(HubService. HUB_BROADCAST_IE_IOTAMSG);
        int result = iotaMsg.getUint(HubService.HUB_IE_RESULT, 0);
        int cookie = iotaMsg.getUint(HubService.HUB_IE_COOKIE, 0);
        return;
    }
};
mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
IntentFilter filterRmvDev = new IntentFilter(HubService.TOPIC_RMVDEV_RSP);
mLocalBroadcastManager.registerReceiver(mDeldeviceRsp, filterRmvDev);
分享:

    相关文档

    相关产品