• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Stationary Development
2
3
4## When to Use
5
6An application can call the **Stationary** module to obtain the device status, for example, whether the device is absolutely or relatively still.
7
8For details about the APIs, see [Stationary](../reference/apis/js-apis-stationary.md).
9
10## Device Status Type Parameters
11
12| Name| Description|
13| -------- | -------- |
14| still | Absolutely still.|
15| relativeStill | Relatively still.|
16
17## Parameters for Subscribing to Device Status events
18
19| Name                            | Value   | Description                                      |
20| ------------------------------ | ---- | ---------------------------------------- |
21| ENTER         | 1    | Event indicating entering device status.  |
22| EXIT | 2   | Event indicating exiting device status.|
23| ENTER_EXIT | 3   | Event indicating entering and exiting device status.|
24
25## Returned Device Status Parameters
26
27| Name                            | Value   | Description                                      |
28| ------------------------------ | ---- | ---------------------------------------- |
29| ENTER         | 1    | Entering device status.  |
30| EXIT | 2   | Exiting device status.|
31
32## Available APIs
33
34| Module         | Name                                                      | Description                                                        |
35| ------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
36| ohos.stationary | on(activity: ActivityType, event: ActivityEvent, reportLatencyNs: number, callback: Callback<ActivityResponse>): void | Subscribes to the device status. This API uses an asynchronous callback to return the result.|
37| ohos.stationary | once(activity: ActivityType, callback: Callback<ActivityResponse>): void | Obtains the device status. This API uses an asynchronous callback to return the result.|
38| ohos.stationary | off(activity: ActivityType, event: ActivityEvent, callback?: Callback<ActivityResponse>): void | Unsubscribes from the device status.                                |
39
40## Constraints
41
42The device must support the acceleration sensor.
43
44## How to Develop
45
461. Subscribe to the event indicating entering the absolute still state, and the event is reported every 1 second.
47
48   ```js
49   import stationary from '@ohos.stationary';
50   var reportLatencyNs = 1000000000;
51   try {
52      stationary.on('still', stationary.ActivityEvent.ENTER, reportLatencyNs, (data) => {
53         console.log('data='+ JSON.stringify(data));
54      })
55   } catch (err) {
56      console.error('errCode: ' + err.code + ' ,msg: ' + err.message);
57   }
58   ```
59
602. Obtain the event indicating entering the absolute still state.
61
62   ```js
63   import stationary from '@ohos.stationary';
64   try {
65      stationary.once('still', (data) => {
66         console.log('data='+ JSON.stringify(data));
67      })
68   } catch (err) {
69      console.error('errCode: ' + err.code + ' ,msg: ' + err.message);
70   }
71   ```
72
733. Unsubscribe from the event indicating entering the absolute still state.
74
75   ```js
76   import stationary from '@ohos.stationary';
77   try {
78      stationary.off('still', stationary.ActivityEvent.ENTER, (data) => {
79         console.log('data='+ JSON.stringify(data));
80      })
81   } catch (err) {
82      console.error('errCode: ' + err.code + ' ,msg: ' + err.message);
83   }
84   ```
85