From f3fdd82da9e1f262cbd5f9a07af3393f94122b3a Mon Sep 17 00:00:00 2001 From: Gloria Date: Thu, 9 Mar 2023 17:55:31 +0800 Subject: [PATCH] Update docs against 14433 Signed-off-by: wusongqing --- en/application-dev/device/Readme-EN.md | 4 +- .../device/stationary-guidelines.md | 84 +++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 en/application-dev/device/stationary-guidelines.md diff --git a/en/application-dev/device/Readme-EN.md b/en/application-dev/device/Readme-EN.md index 6e7fd27fd4..6ce8d1b169 100644 --- a/en/application-dev/device/Readme-EN.md +++ b/en/application-dev/device/Readme-EN.md @@ -1,4 +1,4 @@ -# Device +# Device Management - USB Service - [USB Service Overview](usb-overview.md) @@ -17,3 +17,5 @@ - Update Service - [Sample Server Overview](sample-server-overview.md) - [Sample Server Development](sample-server-guidelines.md) +- Stationary + - [Stationary Development](stationary-guidelines.md) diff --git a/en/application-dev/device/stationary-guidelines.md b/en/application-dev/device/stationary-guidelines.md new file mode 100644 index 0000000000..9f6693027a --- /dev/null +++ b/en/application-dev/device/stationary-guidelines.md @@ -0,0 +1,84 @@ +# Stationary Development + + +## When to Use + +An application can call the **Stationary** module to obtain the device status, for example, whether the device is absolutely or relatively still. + +For details about the APIs, see [Stationary](../reference/apis/js-apis-stationary.md). + +## Device Status Type Parameters + +| Name| Description| +| -------- | -------- | +| still | Absolutely still.| +| relativeStill | Relatively still.| + +## Parameters for Subscribing to Device Status events + +| Name | Value | Description | +| ------------------------------ | ---- | ---------------------------------------- | +| ENTER | 1 | Event indicating entering device status. | +| EXIT | 2 | Event indicating exiting device status.| +| ENTER_EXIT | 3 | Event indicating entering and exiting device status.| + +## Returned Device Status Parameters + +| Name | Value | Description | +| ------------------------------ | ---- | ---------------------------------------- | +| ENTER | 1 | Entering device status. | +| EXIT | 2 | Exiting device status.| + +## Available APIs + +| Module | Name | Description | +| ------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | +| 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.| +| ohos.stationary | once(activity: ActivityType, callback: Callback<ActivityResponse>): void | Obtains the device status. This API uses an asynchronous callback to return the result.| +| ohos.stationary | off(activity: ActivityType, event: ActivityEvent, callback?: Callback<ActivityResponse>): void | Unsubscribes from the device status. | + +## Constraints + +The device must support the acceleration sensor. + +## How to Develop + +1. Subscribe to the event indicating entering the absolute still state, and the event is reported every 1 second. + + ```js + import stationary from '@ohos.stationary'; + var reportLatencyNs = 1000000000; + try { + stationary.on('still', stationary.ActivityEvent.ENTER, reportLatencyNs, (data) => { + console.log('data='+ JSON.stringify(data)); + }) + } catch (err) { + console.error('errCode: ' + err.code + ' ,msg: ' + err.message); + } + ``` + +2. Obtain the event indicating entering the absolute still state. + + ```js + import stationary from '@ohos.stationary'; + try { + stationary.once('still', (data) => { + console.log('data='+ JSON.stringify(data)); + }) + } catch (err) { + console.error('errCode: ' + err.code + ' ,msg: ' + err.message); + } + ``` + +3. Unsubscribe from the event indicating entering the absolute still state. + + ```js + import stationary from '@ohos.stationary'; + try { + stationary.off('still', stationary.ActivityEvent.ENTER, (data) => { + console.log('data='+ JSON.stringify(data)); + }) + } catch (err) { + console.error('errCode: ' + err.code + ' ,msg: ' + err.message); + } + ``` -- GitLab