From aadf1438f714d6a50e8010f6b3c784b67da50fad Mon Sep 17 00:00:00 2001 From: Gloria Date: Thu, 16 Mar 2023 17:00:05 +0800 Subject: [PATCH] Update docs against 15769+16133 Signed-off-by: wusongqing --- .../apis/js-apis-bundle-BundleInstaller.md | 12 +- .../reference/apis/js-apis-system-sensor.md | 471 ++++++++++++------ .../reference/apis/js-apis-system-vibrate.md | 35 +- 3 files changed, 342 insertions(+), 176 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-bundle-BundleInstaller.md b/en/application-dev/reference/apis/js-apis-bundle-BundleInstaller.md index 7523cde565..ff1c5faec3 100644 --- a/en/application-dev/reference/apis/js-apis-bundle-BundleInstaller.md +++ b/en/application-dev/reference/apis/js-apis-bundle-BundleInstaller.md @@ -160,9 +160,9 @@ bundle.getBundleInstaller().then(installer => { Describes the parameters required for bundle installation, recovery, or uninstall. - **System capability**: SystemCapability.BundleManager.BundleFramework +**System capability**: SystemCapability.BundleManager.BundleFramework - **System API**: This is a system API and cannot be called by third-party applications. +**System API**: This is a system API and cannot be called by third-party applications. | Name | Type | Readable| Writable| Description | | ----------- | ------- | ---- | ---- | ------------------ | @@ -174,17 +174,17 @@ Describes the parameters required for bundle installation, recovery, or uninstal Describes the bundle installation or uninstall status. - **System capability**: SystemCapability.BundleManager.BundleFramework +**System capability**: SystemCapability.BundleManager.BundleFramework - **System API**: This is a system API and cannot be called by third-party applications. +**System API**: This is a system API and cannot be called by third-party applications. | Name | Type | Readable| Writable| Description | | ------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------ | -| status | bundle.[InstallErrorCode](js-apis-Bundle.md#installerrorcode) | Yes | No | Installation or uninstall error code. The value must be defined in [InstallErrorCode](js-apis-Bundle.md#installerrorcode). | +| status | bundle.[InstallErrorCode](js-apis-Bundle.md#installerrorcode) | Yes | No | Installation or uninstall error code. The value must be defined in [InstallErrorCode](js-apis-Bundle.md#installerrorcode)| | statusMessage | string | Yes | No | Installation or uninstall status message.
**SUCCESS**: install_succeed
**STATUS_INSTALL_FAILURE**: Installation failed (no installation file exists).
**STATUS_INSTALL_FAILURE_ABORTED**: Installation aborted.
**STATUS_INSTALL_FAILURE_INVALID**: Invalid installation parameter.
**STATUS_INSTALL_FAILURE_CONFLICT**: Installation conflict. (The basic information of the application to update is inconsistent with that of the existing application.)
**STATUS_INSTALL_FAILURE_STORAGE**: Failed to store the bundle information.
**STATUS_INSTALL_FAILURE_INCOMPATIBLE**: Installation incompatibility. (A downgrade occurs or the signature information is incorrect.)
**STATUS_UNINSTALL_FAILURE**: Uninstallation failed. (The application to be uninstalled is not found.)
**STATUS_UNINSTALL_FAILURE_ABORTED**: Uninstallation aborted. (This error code is not in use.)
**STATUS_UNINSTALL_FAILURE_ABORTED**: Uninstallation conflict. (Failed to uninstall a system application or end the application process.)
**STATUS_INSTALL_FAILURE_DOWNLOAD_TIMEOUT**: Installation failed. (Download timed out.)
**STATUS_INSTALL_FAILURE_DOWNLOAD_FAILED**: Installation failed. (Download failed.)
**STATUS_RECOVER_FAILURE_INVALID**: Failed to restore the pre-installed application.
**STATUS_ABILITY_NOT_FOUND**: Ability not found.
**STATUS_BMS_SERVICE_ERROR**: BMS service error.
**STATUS_FAILED_NO_SPACE_LEFT**: Insufficient device space.
**STATUS_GRANT_REQUEST_PERMISSIONS_FAILED**: Application authorization failed.
**STATUS_INSTALL_PERMISSION_DENIED**: No installation permission.
**STATUS_UNINSTALL_PERMISSION_DENIED**: No uninstallation permission. | ## Obtaining the Sandbox Path -For the FA model, the sandbox path of a bundle can be obtained using the APIs in [Context](js-apis-inner-app-context.md). For the stage model, the sandbox path can be obtained using the attribute in [Context](js-apis-ability-context.md#abilitycontext). The following describes how to obtain the sandbox path. +For the FA model, the sandbox path of a bundle can be obtained using the APIs in [Context](js-apis-inner-app-context.md). For the stage model, the sandbox path can be obtained using the attribute in [Context](js-apis-inner-application-uiAbilityContext.md#abilitycontext). The following describes how to obtain the sandbox path. **Example** ``` ts diff --git a/en/application-dev/reference/apis/js-apis-system-sensor.md b/en/application-dev/reference/apis/js-apis-system-sensor.md index 30bfc60e33..ccf4be2ce7 100644 --- a/en/application-dev/reference/apis/js-apis-system-sensor.md +++ b/en/application-dev/reference/apis/js-apis-system-sensor.md @@ -8,7 +8,7 @@ The sensors are classified into the following categories based on their function > **NOTE** > > - The APIs of this module are no longer maintained since API version 8. You are advised to use [`@ohos.sensor`](js-apis-sensor.md) instead. -> - The initial APIs of this module are supported since API version 4. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - This module requires hardware support and can only be debugged on real devices. @@ -19,15 +19,9 @@ The sensors are classified into the following categories based on their function import sensor from '@system.sensor'; ``` -## Error Codes - -| Error Code | Description | -| ---- | -------------- | -| 900 | The current device does not support the corresponding sensor.| - ## sensor.subscribeAccelerometer -subscribeAccelerometer(Object): void + subscribeAccelerometer(options: subscribeAccelerometerOptions): void Subscribes to data changes of the acceleration sensor. If this API is called multiple times for the same application, the last call takes effect. @@ -37,23 +31,13 @@ Subscribes to data changes of the acceleration sensor. If this API is called mul **Parameters** -| Name | Type | Mandatory | Description | -| -------- | -------- | ---- | ---------------------------------------- | -| interval | string | Yes | Execution frequency of the callback for returning the acceleration sensor data.
The default value is **normal**. The options are as follows:
- **game**: called at an interval of 20 ms, which is applicable to gaming scenarios.
- **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.
- **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.| -| success | Function | Yes | Called when the acceleration sensor data changes. | -| fail | Function | No | Callback upon failure. | - -Return values of the success callback - -| Name | Type | Description | -| ---- | ------ | ------- | -| x | number | Acceleration on the x-axis.| -| y | number | Acceleration on the y-axis.| -| z | number | Acceleration on the z-axis.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------ | +| options | [subscribeAccelerometerOptions](#subscribeaccelerometeroptions) | Yes | Type of data to return.| **Example** -``` +```js sensor.subscribeAccelerometer({ interval: 'normal', success: function(ret) { @@ -82,13 +66,13 @@ Unsubscribes from data changes of the acceleration sensor. **Example** -``` +```js sensor.unsubscribeAccelerometer(); ``` ## sensor.subscribeCompass -subscribeCompass(Object): void + subscribeCompass(options: SubscribeCompassOptions): void Subscribes to data changes of the compass sensor. If this API is called multiple times for the same application, the last call takes effect. @@ -96,20 +80,13 @@ Subscribes to data changes of the compass sensor. If this API is called multiple **Parameters** -| Name | Type | Mandatory | Description | -| ------- | -------- | ---- | --------------- | -| success | Function | Yes | Called when the compass sensor data changes.| -| fail | Function | No | Callback upon failure. | - -Return values of the success callback - -| Name | Type | Description | -| --------- | ------ | ---------- | -| direction | number | Direction of the device, in degrees.| +| Name | Type | Mandatory| Description | +| ------- | --------------------------------------------------- | ---- | -------------------------------- | +| options | [SubscribeCompassOptions](#subscribecompassoptions) | Yes | Type of data to return.| **Example** -``` +```js sensor.subscribeCompass({ success: function(ret) { console.log('get data direction:' + ret.direction); @@ -133,13 +110,13 @@ Unsubscribes from data changes of the compass sensor. **Example** -``` +```js sensor.unsubscribeCompass(); ``` ## sensor.subscribeProximity -subscribeProximity(Object): void + subscribeProximity(options: SubscribeProximityOptions): void Subscribes to data changes of the proximity sensor. If this API is called multiple times for the same application, the last call takes effect. @@ -147,20 +124,13 @@ Subscribes to data changes of the proximity sensor. If this API is called multip **Parameters** -| Name | Type | Mandatory | Description | -| ------- | -------- | ---- | ----------------- | -| success | Function | Yes | Called when the proximity sensor data changes.| -| fail | Function | No | Callback upon failure. | - -Return values of the success callback - -| Name | Type | Description | -| -------- | ------ | --------------------- | -| distance | number | Distance between a visible object and the device screen.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------------------- | ---- | -------------------------------- | +| options | [SubscribeProximityOptions](#subscribeproximityoptions) | Yes | Type of data to return.| **Example** -``` +```js sensor.subscribeProximity({ success: function(ret) { console.log('get data distance:' + ret.distance); @@ -184,13 +154,13 @@ Unsubscribes from data changes of the proximity sensor. **Example** -``` +```js sensor.unsubscribeProximity(); ``` ## sensor.subscribeLight -sensor.subscribeLight(Object): void + subscribeLight(options: SubscribeLightOptions): void Subscribes to data changes of the ambient light sensor. If this API is called multiple times, the last call takes effect. @@ -198,20 +168,13 @@ Subscribes to data changes of the ambient light sensor. If this API is called mu **Parameters** -| Name | Type | Mandatory | Description | -| ------- | -------- | ---- | --------------- | -| success | Function | Yes | Called when the ambient light sensor data changes| -| fail | Function | No | Callback upon failure. | - -Return values of the success callback - -| Name | Type | Description | -| --------- | ------ | ------------ | -| intensity | number | Light intensity, in lux.| +| Name | Type | Mandatory| Description | +| ------- | ----------------------------------------------- | ---- | ---------------------------------- | +| options | [SubscribeLightOptions](#subscribelightoptions) | Yes | Type of data to return.| **Example** -``` +```js sensor.subscribeLight({ success: function(ret) { console.log('get data intensity:' + ret.intensity); @@ -235,13 +198,13 @@ Unsubscribes from data changes of the ambient light sensor. **Example** -``` +```js sensor.unsubscribeLight(); ``` ## sensor.subscribeStepCounter -subscribeStepCounter(Object): void + subscribeStepCounter(options: SubscribeStepCounterOptions): void Subscribes to data changes of the step counter sensor. If this API is called multiple times for the same application, the last call takes effect. @@ -251,20 +214,13 @@ Subscribes to data changes of the step counter sensor. If this API is called mul **Parameters** -| Name | Type | Mandatory | Description | -| ------- | -------- | ---- | ---------------- | -| success | Function | Yes | Called when the step counter sensor data changes.| -| fail | Function | No | Callback upon failure. | - -Return values of the success callback - -| Name | Type | Description | -| ----- | ------ | --------------------- | -| steps | number | Number of counted steps after the sensor is restarted.
| +| Name | Type | Mandatory| Description | +| ------- | ----------------------------------------------------------- | ---- | -------------------------------------- | +| options | [SubscribeStepCounterOptions](#subscribestepcounteroptions) | Yes | Type of data to return.| **Example** -``` +```js sensor.subscribeStepCounter({ success: function(ret) { console.log('get step value:' + ret.steps); @@ -290,14 +246,14 @@ Unsubscribes from data changes of the step counter sensor. **Example** -``` +```js sensor.unsubscribeStepCounter(); ``` ## sensor.subscribeBarometer -subscribeBarometer(Object): void +subscribeBarometer(options: SubscribeBarometerOptions): void Subscribes to data changes of the barometer sensor. If this API is called multiple times for the same application, the last call takes effect. @@ -305,20 +261,13 @@ Subscribes to data changes of the barometer sensor. If this API is called multip **Parameters** -| Name | Type | Mandatory | Description | -| ------- | -------- | ---- | ---------------- | -| success | Function | Yes | Called when the barometer sensor data changes.| -| fail | Function | No | Callback upon failure. | - -Return values of the success callback - -| Name | Type | Description | -| -------- | ------ | ----------- | -| pressure | number | Pressure, in pascal.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------------------- | ---- | ---------------------------------- | +| options | [SubscribeBarometerOptions](#subscribebarometeroptions) | Yes | Type of data to return.| **Example** -``` +```js sensor.subscribeBarometer({ success: function(ret) { console.log('get data value:' + ret.pressure); @@ -343,14 +292,14 @@ Unsubscribes from data changes of the barometer sensor. **Example** -``` +```js sensor.unsubscribeBarometer(); ``` ## sensor.subscribeHeartRate -subscribeHeartRate(Object): void + subscribeHeartRate(options: SubscribeHeartRateOptions): void Subscribes to data changes of the heart rate sensor. If this API is called multiple times for the same application, the last call takes effect. @@ -360,20 +309,13 @@ Subscribes to data changes of the heart rate sensor. If this API is called multi **Parameters** -| Name | Type | Mandatory | Description | -| ------- | -------- | ---- | ------------------------- | -| success | Function | Yes | Called when the heart rate sensor data changes. This callback is invoked every five seconds.| -| fail | Function | No | Callback upon failure. | - -Return values of the success callback - -| Name | Type | Description | -| --------- | ------ | ---- | -| heartRate | number | Heart rate.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------------------- | ---- | -------------------------------- | +| options | [SubscribeHeartRateOptions](#subscribeheartrateoptions) | Yes | Type of data to return.| **Example** -``` +```js sensor.subscribeHeartRate({ success: function(ret) { console.log('get heartrate value:' + ret.heartRate); @@ -400,13 +342,13 @@ Unsubscribes from data changes of the heart rate sensor. **Example** -``` +```js sensor.unsubscribeHeartRate(); ``` ## sensor.subscribeOnBodyState -subscribeOnBodyState(Object): void + subscribeOnBodyState(options: SubscribeOnBodyStateOptions): void Subscribes to changes of the wearing state of a wearable device. If this API is called multiple times for the same application, the last call takes effect. @@ -414,20 +356,13 @@ Subscribes to changes of the wearing state of a wearable device. If this API is **Parameters** -| Name | Type | Mandatory | Description | -| ------- | -------- | ---- | ------------- | -| success | Function | Yes | Called when the wearing state changes.| -| fail | Function | No | Callback upon failure. | - -Return values of the success callback - -| Name | Type | Description | -| ----- | ------- | ------ | -| value | boolean | Whether the wearable device is worn.| +| Name | Type | Mandatory| Description | +| ------- | ----------------------------------------------------------- | ---- | ---------------------- | +| options | [SubscribeOnBodyStateOptions](#subscribeonbodystateoptions) | Yes | Type of data to return.| **Example** -``` +```js sensor.subscribeOnBodyState({ success: function(ret) { console.log('get on-body state value:' + ret.value); @@ -451,13 +386,13 @@ Unsubscribes from changes of the wearing state of a wearable device. **Example** -``` +```js sensor.unsubscribeOnBodyState(); ``` ## sensor.getOnBodyState -getOnBodyState(Object): void + getOnBodyState(options: GetOnBodyStateOptions): void Obtains the wearing state of a wearable device. @@ -465,21 +400,13 @@ Obtains the wearing state of a wearable device. **Parameters** -| Name | Type | Mandatory | Description | -| -------- | -------- | ---- | ------------ | -| success | Function | No | Callback upon success.| -| fail | Function | No | Callback upon failure.| -| complete | Function | No | Called when the execution is complete.| - -Return values of the success callback - -| Name | Type | Description | -| ----- | ------- | ------ | -| value | boolean | Whether the wearable device is worn.| +| Name | Type | Mandatory| Description | +| ------- | ----------------------------------------------- | ---- | -------------------------- | +| options | [GetOnBodyStateOptions](#getonbodystateoptions) | Yes | Type of data to return.| **Example** -``` +```js sensor.getOnBodyState({ success: function(ret) { console.log('on body state: ' + ret.value); @@ -492,7 +419,7 @@ sensor.getOnBodyState({ ## sensor.subscribeDeviceOrientation6+ -subscribeDeviceOrientation(interval: string, success: (data: DeviceOrientationResponse), fail?: (data: string, code: number)): void + subscribeDeviceOrientation(options: SubscribeDeviceOrientationOptions): void Subscribes to data changes of the device orientation sensor. @@ -502,22 +429,13 @@ If this API is called multiple times for the same application, the last call tak **Parameters** -| Name | Type | Mandatory | Description | -| -------- | -------- | ---- | ---------------------------------------- | -| interval | string | Yes | Interval at which the callback is invoked to return the device orientation sensor data.
The default value is **normal**. The options are as follows:
- **game**: called at an interval of 20 ms, which is applicable to gaming scenarios.
- **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.
- **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.| -| success | Function | Yes | Called when the device orientation sensor data changes. | -| fail | Function | No | Callback upon failure. | - - Return values of the success callback -| Name | Type | Description | -| ----- | ------ | ---------------------------------------- | -| alpha | number | Rotation angle around the Z axis when the X/Y axis of the device coincides with the X/Y axis of the earth.| -| beta | number | Rotation angle around the X axis when the Y/Z axis of the device coincides with the Y/Z axis of the earth.| -| gamma | number | Rotation angle around the Y axis when the X/Z axis of the device coincides with the X/Z axis of the earth.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------ | +| options | [SubscribeDeviceOrientationOptions](#subscribedeviceorientationoptions) | Yes | Type of data to return.| **Example** -``` +```js sensor.subscribeDeviceOrientation({ interval: 'normal', success: function(ret) { @@ -544,13 +462,13 @@ Unsubscribes from data changes of the device orientation sensor. **Example** -``` +```js sensor.unsubscribeDeviceOrientation(); ``` ## sensor.subscribeGyroscope6+ -subscribeGyroscope(interval: string, success: (data: GyroscopeResponse), fail?: (data: string, code: number)): void + subscribeGyroscope(options: SubscribeGyroscopeOptions): void Subscribes to data changes of the gyroscope sensor. @@ -562,23 +480,13 @@ If this API is called multiple times for the same application, the last call tak **Parameters** -| Name | Type | Mandatory | Description | -| -------- | -------- | ---- | ---------------------------------------- | -| interval | string | Yes | Interval at which the callback is invoked to return the gyroscope sensor data.
The default value is **normal**. The options are as follows:
- **game**: called at an interval of 20 ms, which is applicable to gaming scenarios.
- **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.
- **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.| -| success | Function | Yes | Called when the gyroscope sensor data changes. | -| fail | Function | No | Callback upon failure. | - -Return values of the success callback - -| Name | Type | Description | -| ---- | ------ | --------- | -| x | number | Rotation angular velocity of the X axis.| -| y | number | Rotation angular velocity of the Y axis.| -| z | number | Rotation angular velocity of the Z axis.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------------------- | ---- | ---------------------------------------------- | +| options | [SubscribeGyroscopeOptions](#subscribegyroscopeoptions) | Yes | Type of data to return.| **Example** -``` +```js sensor.subscribeGyroscope({ interval: 'normal', success: function(ret) { @@ -607,6 +515,253 @@ Unsubscribes from data changes of the gyroscope sensor. **Example** -``` +```js sensor.unsubscribeGyroscope(); ``` + +## subscribeAccelerometerOptions + +Defines the type of data to return for a subscription to the acceleration sensor data. + +**Required permissions**: ohos.permission.ACCELEROMETER + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | +| interval | string | Yes | Execution frequency of the callback for returning the acceleration sensor data. The default value is **normal**. The options are as follows: - **game**: called at an interval of 20 ms, which is applicable to gaming scenarios. - **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios. - **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.| +| success | [AccelerometerResponse](#accelerometerresponse) | Yes | Called when the acceleration sensor data changes. | +| fail | Function | No | Callback upon an API call failure. | + +## AccelerometerResponse + +Defines the type of data to include in an **AccelerometerResponse** object. + +**Required permissions**: ohos.permission.ACCELEROMETER + +**System capability**: SystemCapability.Sensors.Sensor + +| Name| Type | Mandatory| Description | +| ---- | ------ | ---- | ------------- | +| x | number | Yes | Acceleration on the x-axis.| +| y | number | Yes | Acceleration on the y-axis.| +| z | number | Yes | Acceleration on the z-axis.| + +## SubscribeCompassOptions + +Defines the type of data to return for a subscription to the compass sensor data. + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| ------- | ----------------------------------- | ---- | ------------------------------ | +| success | [CompassResponse](#compassresponse) | Yes | Called when the compass sensor data changes.| +| fail | Function | No | Callback upon an API call failure. | + +## CompassResponse + +Defines the type of data to include in a **CompassResponse** object. + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | -------------------- | +| direction | number | Yes | Direction of the device, in degrees.| + +## SubscribeProximityOptions + +Defines the type of data to return for a subscription to the proximity sensor data. + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| ------- | --------------------------------------- | ---- | ---------------------------------- | +| success | [ProximityResponse](#proximityresponse) | Yes | Called when the proximity sensor data changes.| +| fail | Function | No | Callback upon an API call failure. | + +## ProximityResponse + +Defines the type of data to include in a **ProximityResponse** object. + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| -------- | ------ | ---- | ------------------------------------------ | +| distance | number | Yes | Distance between a visible object and the device screen.| + +## SubscribeLightOptions + +Defines the type of data to return for a subscription to the ambient light sensor data. + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| ------- | ------------------------------- | ---- | ------------------------------ | +| success | [LightResponse](#lightresponse) | Yes | Called when the ambient light sensor data changes| +| fail | Function | No | Callback upon an API call failure. | + +## LightResponse + +Defines the type of data to include in a **LightResponse** object. + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | --------------------- | +| intensity | number | Yes | Light intensity, in lux.| + +## SubscribeStepCounterOptions + +Defines the type of data to return for a subscription to the step counter sensor data. + +**Required permissions**: ohos.permission.ACTIVITY_MOTION + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------- | ---- | -------------------------------- | +| success | [StepCounterResponse](#stepcounterresponse) | Yes | Called when the step counter sensor data changes.| +| fail | Function | No | Callback upon an API call failure. | + +## StepCounterResponse + +Defines the type of data to include in a **StepCounterResponse** object. + +**Required permissions**: ohos.permission.ACTIVITY_MOTION + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| ----- | ------ | ---- | -------------------------------- | +| steps | number | Yes | Number of counted steps after the sensor is restarted.| + +## SubscribeBarometerOptions + +Defines the type of data to return for a subscription to the barometer sensor data. + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| ------- | --------------------------------------- | ---- | -------------------------------- | +| success | [BarometerResponse](#barometerresponse) | Yes | Called when the barometer sensor data changes.| +| fail | Function | No | Callback upon an API call failure. | + +## BarometerResponse + +Defines the type of data to include in a **BarometerResponse** object. + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| -------- | ------ | ---- | ---------------------- | +| pressure | number | Yes | Pressure, in pascal.| + +## SubscribeHeartRateOptions + +Defines the type of data to return for a subscription to the heart rate sensor data. + +**Required permissions**: ohos.permission.READ_HEALTH_DATA + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| ------- | --------------------------------------- | ---- | ----------------------------------------------- | +| success | [HeartRateResponse](#heartrateresponse) | Yes | Called when the heart rate sensor data changes. This callback is invoked every five seconds.| +| fail | Function | No | Callback upon an API call failure. | + +## HeartRateResponse + +Defines the type of data to include in a **HeartRateResponse** object. + +**Required permissions**: ohos.permission.READ_HEALTH_DATA + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | -------- | +| heartRate | number | Yes | Heart rate.| + +## SubscribeOnBodyStateOptions + +Defines the type of data to return for a subscription to the wearing state changes. + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------- | ---- | -------------------------- | +| success | [OnBodyStateResponse](#onbodystateresponse) | Yes | Called when the wearing state changes.| +| fail | Function | No | Callback upon an API call failure. | + +## OnBodyStateResponse + +Defines the wearing state. + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| ----- | ------- | ---- | ------------ | +| value | boolean | Yes | Whether the wearable device is worn.| + +## GetOnBodyStateOptions + + Defines the type of data to return for obtaining the wearing state. + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------- | ---- | ------------------------ | +| success | [OnBodyStateResponse](#onbodystateresponse) | No | Callback upon a successful API call.| +| fail | Function | No | Callback upon an API call failure.| +| complete | Function | No | Called when the API call is complete.| + +## SubscribeDeviceOrientationOptions6+ + +Defines the type of data to return for a subscription to the device orientation sensor data. + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| interval | string | Yes | Interval at which the callback is invoked to return the device orientation sensor data.
The default value is **normal**. The options are as follows:
- **game**: called at an interval of 20 ms, which is applicable to gaming scenarios.
- **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.
- **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.| +| success | [DeviceOrientationResponse](#deviceorientationresponse) | Yes | Called when the device orientation sensor data changes. | +| fail | Function | No | Callback upon an API call failure. | + +## DeviceOrientationResponse6+ + +Defines the type of data to include in a **DeviceOrientationResponse** object. + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| ----- | ------ | ---- | ------------------------------------------------------------ | +| alpha | number | Yes | Rotation angle around the Z axis when the X/Y axis of the device coincides with the X/Y axis of the earth.| +| beta | number | Yes | Rotation angle around the X axis when the Y/Z axis of the device coincides with the Y/Z axis of the earth.| +| gamma | number | Yes | Rotation angle around the Y axis when the X/Z axis of the device coincides with the X/Z axis of the earth.| + +## SubscribeGyroscopeOptions6+ + +Defines the type of data to return for a subscription to the gyroscope sensor data. + +**Required permissions**: ohos.permission.GYROSCOPE + +**System capability**: SystemCapability.Sensors.Sensor + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | +| interval | string | Yes | Interval at which the callback is invoked to return the gyroscope sensor data.
The default value is **normal**. The options are as follows:
- **game**: called at an interval of 20 ms, which is applicable to gaming scenarios.
- **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.
- **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.| +| success | [GyroscopeResponse](#gyroscoperesponse) | Yes | Called when the gyroscope sensor data changes. | +| fail | Function | No | Callback upon an API call failure. | + +## GyroscopeResponse6+ + +Defines the type of data to include in a **GyroscopeResponse** object. + +**Required permissions**: ohos.permission.GYROSCOPE + +**System capability**: SystemCapability.Sensors.Sensor + +| Name| Type | Mandatory| Description | +| ---- | ------ | ---- | ----------------- | +| x | number | Yes | Rotation angular velocity of the X axis.| +| y | number | Yes | Rotation angular velocity of the Y axis.| +| z | number | Yes | Rotation angular velocity of the Z axis.| diff --git a/en/application-dev/reference/apis/js-apis-system-vibrate.md b/en/application-dev/reference/apis/js-apis-system-vibrate.md index 90dc19e2ff..a48f2f453f 100644 --- a/en/application-dev/reference/apis/js-apis-system-vibrate.md +++ b/en/application-dev/reference/apis/js-apis-system-vibrate.md @@ -1,13 +1,12 @@ # @system.vibrator (Vibrator) - The **Vibrator** module provides APIs for controlling LED lights and vibrators. You can use the APIs to query the LED light list, turn on and off the LED light, query the vibrator list, query the vibrator effect, and trigger and turn off the vibrator. Misc devices refer to LED lights and vibrators on devices. LED lights are mainly used for indication (for example, indicating the charging state) and blinking (such as tri-colored lights). Vibrators are mainly used in scenarios such as the alarm clock, power-on/off, and incoming call vibration. > **NOTE** -> - The initial APIs of this module are supported since API version 4. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The APIs of this module are no longer maintained since API version 8. You are advised to use [`@ohos.vibrator`](js-apis-vibrator.md) instead. > - This module requires hardware support and can only be debugged on real devices. @@ -21,26 +20,23 @@ import vibrator from '@system.vibrator'; ## vibrator.vibrate -vibrate(Object): void + vibrate(options?: VibrateOptions): void Triggers device vibration. -**System capability**: SystemCapability.Sensors.MiscDevice +**Required permissions**: ohos.permission.VIBRATE -**Required permissions**: ohos.permission.VIBRATE (a system permission) +**System capability**: SystemCapability.Sensors.MiscDevice **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| mode | string | No| Vibration mode. The value **long** indicates long vibration, and **short** indicates short vibration. The default value is **long**.| -| success | Function | Yes| Called when the vibrator data changes.| -| fail | Function | No| Called when the API call fails.| -| complete | Function | No| Called when the API call is complete.| +| Name | Type | Mandatory| Description | +| ------- | --------------------------------- | ---- | ---------- | +| options | [VibrateOptions](#vibrateoptions) | No | Vibration options.| **Example** -``` +```js vibrator.vibrate({ mode: 'short', success: function() { @@ -54,3 +50,18 @@ vibrator.vibrate({ } }); ``` + +## VibrateOptions + +Defines the vibration options. + +**Required permissions**: ohos.permission.VIBRATE + +**System capability**: SystemCapability.Sensors.MiscDevice + +| Name | Type | Mandatory| Description | +| -------- | -------- | ---- | ------------------------------------------------------------ | +| mode | string | No | Vibration mode. The value **long** indicates long vibration, and **short** indicates short vibration. The default value is **long**.| +| success | Function | No | Called when the vibrator data changes. | +| fail | Function | No | Called when the API call fails. | +| complete | Function | No | Called when the API call is complete. | -- GitLab