harmony 鸿蒙Device Status Awareness Development
Device Status Awareness Development
The DeviceStatus module provides device status awareness capabilities such as obtaining the steady standing state (that is, stand mode).
For details about the APIs, see the API Reference.
Concepts
Understanding the following concepts would be helpful for you in device status awareness development:
Stand moe
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 foldable smartphones, the device must be in a folded state or fully unfolded state.
How to Develop
Overview
During development, subscribe to steady standing state change events and obtain the current state through the callback passed in during subscription.
Constraints
The device must support the accelerometer and specific chips.
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. This API returns the result through a callback. |
Development Procedure
- Import the deviceStatus module.
import { deviceStatus } from '@kit.MultimodalAwarenessKit';
- Subscribe to steady standing state change events.
try {
deviceStatus.on('steadyStandingDetect', (data:deviceStatus.SteadyStandingStatus) => {
console.info('now status = ' + data);
});
} catch (err) {
console.info('on failed, err = ' + err);
}
- Unsubscribe from all callbacks of steady standing state change events.
try {
deviceStatus.off('steadyStandingDetect');
} catch (err) {
console.info('off failed, err = ' + err);
}
- Unsubscribe from the specific callback of steady standing state change events.
import { Callback } from '@ohos.base';
// Define the callback variable.
let callback : Callback<deviceStatus.SteadyStandingStatus> = (data : deviceStatus.SteadyStandingStatus) => {
console.info('now status = ' + data);
};
// Subscribe to a specific callback of steady standing state change events.
try {
deviceStatus.on('steadyStandingDetect', callback);
} catch (err) {
console.info('on failed, err = ' + err);
}
// Unsubscribe from the specific callback of steady standing state change events.
try {
deviceStatus.off('steadyStandingDetect', callback);
} catch (err) {
console.info('off failed, err = ' + err);
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Multimodal Awareness Kit
harmony 鸿蒙Motion Awareness Development
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦