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).
Understanding the following concepts would be helpful for you in device status awareness development:
Stand mode
A device enters stand mode when it is stationary, and its screen is at an angle between 45 and 135 degrees relative to the horizontal plane. For a foldable, it must be in a folded state or fully unfolded state.
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.
| 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. |
import { deviceStatus } from '@kit.MultimodalAwarenessKit'; try {
deviceStatus.on('steadyStandingDetect', (data:deviceStatus.SteadyStandingStatus) => {
console.info('succeed to get status, now status = ' + data);
});
// ...
} catch (err) {
console.error('on failed, err = ' + err);
// ...
} try {
deviceStatus.off('steadyStandingDetect');
// ...
} catch (err) {
console.error('off failed, err = ' + err);
// ...
} // 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);
// ...
}