• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.multimodalAwareness.deviceStatus (Device Status Awareness)
2
3The deviceStatus module provides the device status awareness functionality.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 18. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11  ```ts
12  import { deviceStatus } from '@kit.MultimodalAwarenessKit';
13  ```
14
15## SteadyStandingStatus
16
17Defines the steady standing state (that is, stand mode).
18
19A 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**System capability**: SystemCapability.MultimodalAwareness.DeviceStatus
22
23| Name               | Value  | Description                  |
24| ------------------- | ---- | ---------------------- |
25| STATUS_EXIT  | 0    | Exit of the stand mode.|
26| STATUS_ENTER | 1    | Entry to the stand mode.|
27
28## deviceStatus.on('steadyStandingDetect')
29
30 on(type: 'steadyStandingDetect', callback: Callback<SteadyStandingStatus>): void;
31
32Subscribes to steady standing state events.
33
34**System capability**: SystemCapability.MultimodalAwareness.DeviceStatus
35
36**Parameters**
37
38| Name  | Type                            | Mandatory| Description                                                        |
39| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
40| type     | string                           | Yes  | Event type. This field has a fixed value of **steadyStandingDetect**.|
41| callback | Callback<[SteadyStandingStatus](#steadystandingstatus)> | Yes  | Callback used to return the steady standing state of the device.|
42
43**Error codes**
44
45For details about the error codes, see [Device Status Awareness Error Codes](errorcode-deviceStatus.md) and [Universal Error Codes](../errorcode-universal.md).
46
47| ID| Error Message                                                    |
48| -------- | ------------------------------------------------------------ |
49| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. |
50| 801      | Capability not supported. Function can not work correctly due to limited device capabilities. |
51| 32500001 | Service exception. |
52| 32500002 | Subscription failed. |
53
54**Example**
55
56  ```ts
57  try {
58    deviceStatus.on('steadyStandingDetect', (data:deviceStatus.SteadyStandingStatus) => {
59      console.info('now status = ' + data);
60    });
61  } catch (err) {
62    console.info('on failed, err = ' + err);
63  }
64  ```
65
66## deviceStatus.off('steadyStandingDetect')
67
68off(type: 'steadyStandingDetect', callback?: Callback<SteadyStandingStatus>): void;
69
70Unsubscribes from steady standing state events.
71
72**System capability**: SystemCapability.MultimodalAwareness.DeviceStatus
73
74**Parameters**
75
76| Name  | Type                            | Mandatory| Description                                                        |
77| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
78| type     | string                           | Yes  | Event type. This field has a fixed value of **steadyStandingDetect**.|
79| callback | Callback<[SteadyStandingStatus](#steadystandingstatus)> | Yes  | Callback used to return the steady standing state of the device.|
80
81**Error codes**
82
83For details about the error codes, see [Device Status Awareness Error Codes](errorcode-deviceStatus.md) and [Universal Error Codes](../errorcode-universal.md).
84
85| ID| Error Message                                                    |
86| -------- | ------------------------------------------------------------ |
87| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. |
88| 801      | Capability not supported. Function can not work correctly due to limited device capabilities. |
89| 32500001 | Service exception. |
90| 32500003 | Unsubscription failed. |
91
92**Example**
93
94Example 1: Unsubscribe from all callbacks of steady standing state change events.
95
96  ```ts
97  try {
98    deviceStatus.off('steadyStandingDetect');
99  } catch (err) {
100    console.info('off failed, err = ' + err);
101  }
102  ```
103
104Example 2: Unsubscribe from a specific callback of steady standing state change events.
105
106  ```ts
107  import { Callback } from '@ohos.base';
108  // Define the callback variable.
109  let callback : Callback<deviceStatus.SteadyStandingStatus> = (data : deviceStatus.SteadyStandingStatus) => {
110    console.info('now status = ' + data);
111  };
112  // Subscribe to a specific callback of steady standing state change events.
113  try {
114    deviceStatus.on('steadyStandingDetect', callback);
115  } catch (err) {
116    console.info('on failed, err = ' + err);
117  }
118  // Unsubscribe from the specific callback of steady standing state change events.
119  try {
120    deviceStatus.off('steadyStandingDetect', callback);
121  } catch (err) {
122    console.info('off failed, err = ' + err);
123  }
124  ```
125