目录

Device Status Awareness Development

The DeviceStatus module provides device status awareness capabilities. It can be used to obtain device information, such as the steady standing state (stand mode).

For details about the APIs, see @ohos.multimodalAwareness.deviceStatus (Device Status Awareness).

Concepts

Understanding the following concepts would be helpful for you in device status awareness development:

How to Develop

[h2]Overview

During development, you can subscribe to steady standing state change events and obtain the current state through the callback passed in during subscription.

This function is supported since API version 18.

[h2]Constraints

The device must support accelerometers.

[h2]APIs

API Description
on(type: 'steadyStandingDetect', callback: Callback<SteadyStandingStatus>): void; Subscribes to steady standing state change events. This API returns the result through a callback.
off(type: 'steadyStandingDetect', callback?: Callback<SteadyStandingStatus>): void; Unsubscribes from steady standing state change events.

[h2]Development Procedure

  1. Import the deviceStatus module.
import { deviceStatus } from '@kit.MultimodalAwarenessKit';
  1. Subscribe to steady standing state change events.
try {
  deviceStatus.on('steadyStandingDetect', (data:deviceStatus.SteadyStandingStatus) => {
    console.info('succeed to get status, now status = ' + data);
  });
  // ...
} catch (err) {
  console.error('on failed, err = ' + err);
  // ...
}
  1. Unsubscribe from all steady standing state change events subscribed by this client.
try {
  deviceStatus.off('steadyStandingDetect');
  // ...
} catch (err) {
  console.error('off failed, err = ' + err);
  // ...
}
  1. Unsubscribe from the specific callback of steady standing state change events.
// Define the callback variable.
let callback : Callback<deviceStatus.SteadyStandingStatus> = (data : deviceStatus.SteadyStandingStatus) => {
  console.info('succeed to get status, now status = ' + data);
};
// Subscribe to the device stationary posture perception (steady standing) event using the callback.
try {
  deviceStatus.on('steadyStandingDetect', callback);
  // ...
} catch (err) {
  console.error('on failed, err = ' + err);
  // ...
}
// Unsubscribe the specific callback for the device stationary posture perception (steady standing) event on this client.
try {
  deviceStatus.off('steadyStandingDetect', callback);
  // ...
} catch (err) {
  console.error('off failed, err = ' + err);
  // ...
}