Help Center > > API Reference> AgentLite API Reference (Android)> APIs> Receiving a Command

Receiving a Command

Updated at: Aug 28, 2019 GMT+08:00

API Function

This API is used to register the broadcast for receiving control commands from the IoT platform.

API Description

1
DataTransService.TOPIC_COMMAND_RECEIVE;

Parameter Description

N/A

Output

Broadcast Name

Broadcast Parameter

Member

Description

TOPIC_COMMAND_RECEIVE

IotaMessage

(Obtained by using intent.getSerializableExtra(DataTransService.DATATRANS_BROADCAST_IE_IOTAMSG))

DATATRANS_IE_REQUESTID

Identifies a request.

DATATRANS_IE_DEVICEID

Specifies the logical ID of a device, which is allocated by the IoT platform when the device is added.

DATATRANS_IE_SERVICEID

Identifies a service.

DATATRANS_IE_METHOD

Specifies the service method.

DATATRANS_IE_CMDCONTENT

Specifies the command content.

Example

Register a broadcast receiver to process the command reception.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
BroadcastReceiver mReceiveCmd;
mReceiveCmd = new BroadcastReceiver() {
    @Override 
    public void onReceive(Context context, Intent intent) {
        //Do Something 
        IotaMessage iotaMsg = (IotaMessage)intent.getSerializableExtra(DataTransService. DATATRANS_BROADCAST_IE_IOTAMSG);
        String requstId = iotaMsg.getString(DataTransService.DATATRANS_IE_REQUESTID);
        String deviceId = iotaMsg.getString(DataTransService.DATATRANS_IE_DEVICEID);
        String serviceId = iotaMsg.getString(DataTransService.DATATRANS_IE_SERVICEID);
        String method = iotaMsg.getString(DataTransService.DATATRANS_IE_METHOD);
        String cmdContent = iotaMsg.getString(DataTransService.DATATRANS_IE_CMDCONTENT);
if (serviceId.equals("switch"))
        {
     //Use the JSON component to parse cmdContent based on the command parameters defined by the profile.
            //Send command to Switch
        }
        return;
    }
};
mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
IntentFilter filterReceiveCmd 
 = new IntentFilter(DataTransService.TOPIC_COMMAND_RECEIVE);
mLocalBroadcastManager.registerReceiver(mReceiveCmd, filterReceiveCmd);

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel