Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Before using this API, apply for the required permission from the user on the phone (by referring to Requesting User Authorization).
| Wearable Status and Health Status | Permission | Query Result | Trigger Condition for Subscription | Subscription Result |
|---|---|---|---|---|
| Connection | Basic device information | N/A Check the connection status of the wearable device by referring to Querying Wearable Device Information. |
|
|
| Available space | Available space (for example: 20480) | N/A | N/A | |
| Battery | Battery level (for example, 97) | The battery level of the wearable device decreases by 1% (for example, from 98% to 97%), and the device is not being charged. | Battery level (for example, 97) | |
| Charging |
|
|
| |
| Device mode |
|
|
| |
| Wearing | Wearable user status WEAR_USER_STATUS (only for enterprise developers) |
|
|
|
| Heart rate alerts | N/A |
Note: Open the Huawei Health app, touch Devices and the connected device, and go to . (The "heart rate" refers to the "resting heart rate".) |
|
// Step 2: Obtain the DeviceClient object.
DeviceClient deviceClient = HiWear.getDeviceClient(this);
// Step 3: Obtain the available space of the specified device.
if (connectedDevice != null && connectedDevice.isConnected()) {
deviceClient.getAvailableKbytes(connectedDevice).addOnSuccessListener(new OnSuccessListener<Integer>() {
@Override
public void onSuccess(Integer integer) {
// Return the available storage space (KB) of a specified device.
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
// Process the logic related to the failure to query the available storage space of a specified device.
}
});
} In addition to the available space, other states of the wearable device and health data may be obtained by calling the query method in the MonitorClient object. A maximum of one status can be queried at one time.
// Step 2: Obtain the MonitorClient object.
MonitorClient monitorClient = HiWear.getMonitorClient(this);
// Step 3: Query the status of the specified indicator.
if (connectedDevice != null && connectedDevice.isConnected()) {
monitorClient.query(connectedDevice, MonitorItem.MONITOR_ITEM_WEAR)
.addOnSuccessListener(new OnSuccessListener<MonitorData>() {
@Override
public void onSuccess(MonitorData monitorData) {
// Process the events related to the successful query.
int wearStatus = monitorData.asInt();
// 1: worn
// 2: not worn
if(wearStatus == 1){
// Process the logic related to the wearing status.
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
// Process the events related to the failed query.
}
});
} Sample code (Subscribing to the wearing status is used as an example.)
// Step 2: Obtain the MonitorClient object.
MonitorClient monitorClient = HiWear.getMonitorClient(this);
// Step 3: Define the callback object of the subscribed task.
MonitorListener monitorListener = new MonitorListener() {
@Override
public void onChanged(int errorCode, MonitorItem monitorItem, MonitorData monitorData) {
// Process the status change of the specified indicator of the wearable device.
// Determine the wearing status of the device.
if(MonitorItem.MONITOR_ITEM_WEAR.getName().equals(monitorItem.getName())){
int wearStatus = monitorData.asInt();
// 1: worn
// 2: not worn
if(wearStatus == 1){
// Process the logic related to the wearing status.
}
}
}
};
//Step 4: Subscribe to the wearing status changes.
if (connectedDevice != null && connectedDevice.isConnected()) {
monitorClient.register(connectedDevice, MonitorItem.MONITOR_ITEM_WEAR, monitorListener)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void successVoid) {
// Process the events related to the successful subscription.
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
// Process the events related to the failed subscription.
}
});
} monitorClient.unregister(monitorListener);
// Step 2: Obtain the MonitorClient object.
MonitorClient monitorClient = HiWear.getMonitorClient(this);
// Step 3: Define the callback object of the subscribed task.
MonitorListener monitorListener = new MonitorListener() {
@Override
public void onChanged(int errorCode, MonitorItem monitorItem, MonitorData monitorData) {
// Process the status change of the specified indicator of the wearable device.
// Check whether the device is switched. If the device is switched, use the getBondedDevices method to obtain the device that has been paired with the Huawei Health app by referring to section "Querying Wearable Device Information". In addition, you can call the device.isConnected() method to obtain the device that is currently connected.
if(MonitorItem.MONITOR_ITEM_CONNECTION.getName().equals(monitorItem.getName())){
int connectionStatus = monitorData.asInt();
// 2: Connected
// 3: Disconnected
// 4: Unable to connect
if(connectionStatus == 3){
// Process the logic related to the disconnection.
}
}
}
};
ArrayList<MonitorItem> monitorItemList = new ArrayList<>();
monitorItemList.add(MonitorItem.MONITOR_ITEM_CONNECTION);
monitorItemList.add(MonitorItem.MONITOR_ITEM_LOW_POWER);
monitorItemList.add(MonitorItem.MONITOR_ITEM_WEAR);
monitorItemList.add(MonitorItem.MONITOR_CHARGE_STATUS);
monitorItemList.add(MonitorItem.MONITOR_ITEM_HEART_RATE_ALARM);
// Step 4: Subscribe to the status changes of multiple indicators.
if (connectedDevice != null && connectedDevice.isConnected()) {
monitorClient.register(connectedDevice, monitorItemList, monitorListener)
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
// Process the events related to the failed subscription.
}
})
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void successVoid) {
// Process the events related to the successful subscription.
}
});
} monitorClient.unregister(monitorListener);