• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Device Status Awareness Development
2<!--Kit: Multimodal Awareness Kit-->
3<!--Subsystem: MultimodalAwareness-->
4<!--Owner: @dilligencer-->
5<!--Designer: @zou_ye-->
6<!--Tester: @judan-->
7<!--Adviser: @hu-zhiqiong-->
8
9The DeviceStatus module provides device status awareness capabilities such as obtaining the steady standing state (that is, stand mode).
10
11For details about the APIs, see the [API Reference](../../reference/apis-multimodalawareness-kit/js-apis-awareness-deviceStatus.md).
12
13## Concepts
14
15Understanding the following concepts would be helpful for you in device status awareness development:
16
17- Stand mode
18
19    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.
20
21## How to Develop
22
23### Overview
24
25During development, subscribe to steady standing state change events and obtain the current state through the callback passed in during subscription.
26
27### Constraints
28
29The device must support accelerometers.
30
31### APIs
32
33| API                                                      | Description                                  |
34| ------------------------------------------------------------ | -------------------------------------- |
35| on(type: 'steadyStandingDetect', callback: Callback&lt;SteadyStandingStatus&gt;): void; | Subscribes to steady standing state change events. This API returns the result through a callback.|
36| off(type: 'steadyStandingDetect', callback: Callback&lt;SteadyStandingStatus&gt;): void; | Unsubscribes from steady standing state change events. This API returns the result through a callback.                  |
37
38### Development Procedure
39
401. Import the **deviceStatus** module.
41
42  ```ts
43  import { deviceStatus } from '@kit.MultimodalAwarenessKit';
44  ```
45
462. Subscribe to steady standing state change events.
47
48  ```ts
49  try {
50    deviceStatus.on('steadyStandingDetect', (data:deviceStatus.SteadyStandingStatus) => {
51      console.info('now status = ' + data);
52    });
53  } catch (err) {
54    console.info('on failed, err = ' + err);
55  }
56  ```
57
583. Unsubscribe from all callbacks of steady standing state change events.
59
60  ```ts
61  try {
62    deviceStatus.off('steadyStandingDetect');
63  } catch (err) {
64    console.info('off failed, err = ' + err);
65  }
66  ```
67
684. Unsubscribe from the specific callback of steady standing state change events.
69
70  ```ts
71  import { Callback } from '@ohos.base';
72  // Define the callback variable.
73  let callback : Callback<deviceStatus.SteadyStandingStatus> = (data : deviceStatus.SteadyStandingStatus) => {
74    console.info('now status = ' + data);
75  };
76  // Subscribe to a specific callback of steady standing state change events.
77  try {
78    deviceStatus.on('steadyStandingDetect', callback);
79  } catch (err) {
80    console.info('on failed, err = ' + err);
81  }
82  // Unsubscribe from the specific callback of steady standing state change events.
83  try {
84    deviceStatus.off('steadyStandingDetect', callback);
85  } catch (err) {
86    console.info('off failed, err = ' + err);
87  }
88  ```
89