设备管理 IOTDM(联通用户专用)-设备绑定:示例

时间:2024-07-03 16:54:07

示例

调用设备绑定接口。

1
BindService.bind(new IotaDeviceInfo("nodeId", "manufacturerId", " Gateway", "model", "protocolType")); 

接收设备绑定响应消息。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
//当设备成功绑定之后,Agent Lite会返回给UI如下几个参数,需要UI进行持久化存储,设备登录前需要提前进行配置 
BroadcastReceiver mBindRsp; 
mBindRsp = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
    //Do Something 
    IotaMessage iotaMsg = (IotaMessage)intent.getSerializableExtra(BindService.BIND_BROADCAST_MSG_IE_IOTAMSG); 
    int result = iotaMsg.getUint(BindService.BIND_IE_RESULT, 0); 
    String deviceId = iotaMsg.getString(BindService.BIND_IE_DEVICEID); 
    String Secret = iotaMsg.getString(BindService.BIND_IE_DEVI CES ECRET); 
    String Appid = iotaMsg.getString(BindService.BIND_IE_APPID); 
    String haAddr = iotaMsg.getString(BindService.BIND_IE_HA_ADDR); 
    String lvsAddr = iotaMsg.getString(BindService.BIND_IE_LVS_ADDR); 
    return;  
    } 
}; 
mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); 
IntentFilter filterBind = new IntentFilter(BindService.TOPIC_BINDDEVICE_RSP); 
mLocalBroadcastManager.registerReceiver(mBindRsp, filterBind);
support.huaweicloud.com/sdkreference-iot/iot_06_1008.html