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