提交 531b12a8 编写于 作者: G Gloria

Update docs against 11324+11569+11993+11346+11485+11812

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 578c5ce2
# Vibrator # Vibrator
The **Vibrator** module provides APIs for triggering or stopping vibration. The **vibrator** module provides APIs for starting or stopping vibration.
> **NOTE** > **NOTE**
> >
...@@ -17,7 +17,7 @@ import vibrator from '@ohos.vibrator'; ...@@ -17,7 +17,7 @@ import vibrator from '@ohos.vibrator';
startVibration(effect: VibrateEffect, attribute: VibrateAttribute, callback: AsyncCallback&lt;void&gt;): void startVibration(effect: VibrateEffect, attribute: VibrateAttribute, callback: AsyncCallback&lt;void&gt;): void
Triggers vibration with the specified effect and attribute. This API uses a promise to return the result. Starts vibration with the specified effect and attribute. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.VIBRATE **Required permissions**: ohos.permission.VIBRATE
...@@ -29,35 +29,35 @@ Triggers vibration with the specified effect and attribute. This API uses a prom ...@@ -29,35 +29,35 @@ Triggers vibration with the specified effect and attribute. This API uses a prom
| --------- | -------------------------------------- | ---- | :--------------------------------------------------------- | | --------- | -------------------------------------- | ---- | :--------------------------------------------------------- |
| effect | [VibrateEffect](#vibrateeffect9) | Yes | Vibration effect. | | effect | [VibrateEffect](#vibrateeffect9) | Yes | Vibration effect. |
| attribute | [VibrateAttribute](#vibrateattribute9) | Yes | Vibration attribute. | | attribute | [VibrateAttribute](#vibrateattribute9) | Yes | Vibration attribute. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to the result. If the vibration starts, **err** is **undefined**. Otherwise, **err** is an error object.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the vibration starts, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes** **Error codes**
For details about the error codes, see [Vibrator Error Codes](../errorcodes/errorcode-vibrator.md). For details about the error codes, see [Vibrator Error Codes](../errorcodes/errorcode-vibrator.md).
| ID| Error Message | | ID| Error Message |
| -------- | ------------------------- | | -------- | ------------------------ |
| 14600101 | Device operation failed.| | 14600101 | Device operation failed. |
**Example** **Example**
```js ```js
try { try {
vibrator.startVibration({ vibrator.startVibration({
type:'time', type: 'time',
duration:1000, duration: 1000,
},{ }, {
id:0, id: 0,
usage: 'alarm' usage: 'alarm'
}, (error)=>{ }, (error) => {
if(error){ if (error) {
console.log('vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message); console.error('vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message);
}else{ return;
console.log('Callback returned to indicate a successful vibration.');
} }
console.log('Callback returned to indicate a successful vibration.');
}); });
} catch(err) { } catch (err) {
console.info('errCode: ' + err.code + ' ,msg: ' + err.message); console.error('errCode: ' + err.code + ' ,msg: ' + err.message);
} }
``` ```
...@@ -65,7 +65,7 @@ try { ...@@ -65,7 +65,7 @@ try {
startVibration(effect: VibrateEffect, attribute: VibrateAttribute): Promise&lt;void&gt; startVibration(effect: VibrateEffect, attribute: VibrateAttribute): Promise&lt;void&gt;
Triggers vibration with the specified effect and attribute. This API uses a promise to return the result. Starts vibration with the specified effect and attribute. This API uses a promise to return the result.
**Required permissions**: ohos.permission.VIBRATE **Required permissions**: ohos.permission.VIBRATE
...@@ -88,27 +88,27 @@ Triggers vibration with the specified effect and attribute. This API uses a prom ...@@ -88,27 +88,27 @@ Triggers vibration with the specified effect and attribute. This API uses a prom
For details about the error codes, see [Vibrator Error Codes](../errorcodes/errorcode-vibrator.md). For details about the error codes, see [Vibrator Error Codes](../errorcodes/errorcode-vibrator.md).
| ID| Error Message | | ID| Error Message |
| -------- | ------------------------- | | -------- | ------------------------ |
| 14600101 | Device operation failed.| | 14600101 | Device operation failed. |
**Example** **Example**
```js ```js
try { try {
vibrator.startVibration({ vibrator.startVibration({
type: 'time', type: 'time',
duration: 1000 duration: 1000
}, { }, {
id: 0, id: 0,
usage: 'alarm' usage: 'alarm'
}).then(()=>{ }).then(() => {
console.log('Promise returned to indicate a successful vibration'); console.log('Promise returned to indicate a successful vibration');
}).catch((error)=>{ }, (error) => {
console.log('error.code' + error.code + 'error.message' + error.message); console.error('error.code' + error.code + 'error.message' + error.message);
}) });
} catch(err) { } catch (err) {
console.info('errCode: ' + err.code + ' ,msg: ' + err.message); console.error('errCode: ' + err.code + ' ,msg: ' + err.message);
} }
``` ```
...@@ -116,7 +116,7 @@ try { ...@@ -116,7 +116,7 @@ try {
stopVibration(stopMode: VibratorStopMode, callback: AsyncCallback&lt;void&gt;): void stopVibration(stopMode: VibratorStopMode, callback: AsyncCallback&lt;void&gt;): void
Stops the vibration with the specified **stopMode**. This API uses a promise to return the result. If the specified **stopMode** is different from the mode used to trigger the vibration, this API fails to be called. Stops vibration in the specified mode. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.VIBRATE **Required permissions**: ohos.permission.VIBRATE
...@@ -127,21 +127,41 @@ Stops the vibration with the specified **stopMode**. This API uses a promise to ...@@ -127,21 +127,41 @@ Stops the vibration with the specified **stopMode**. This API uses a promise to
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------------- | ---- | ------------------------------------------------------------ |
| stopMode | [VibratorStopMode](#vibratorstopmode) | Yes | Mode to stop the vibration. | | stopMode | [VibratorStopMode](#vibratorstopmode) | Yes | Mode to stop the vibration. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to the result. If the vibration stops, **err** is **undefined**. Otherwise, **err** is an error object.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the vibration stops, **err** is **undefined**; otherwise, **err** is an error object.|
**Example** **Example**
```js ```js
try { try {
vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function(error){ // Start vibration at a fixed duration.
if(error){ vibrator.startVibration({
type: 'time',
duration: 1000,
}, {
id: 0,
usage: 'alarm'
}, (error) => {
if (error) {
console.error('vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message);
return;
}
console.log('Callback returned to indicate a successful vibration.');
});
} catch (err) {
console.error('errCode: ' + err.code + ' ,msg: ' + err.message);
}
try {
// Stop vibration in VIBRATOR_STOP_MODE_TIME mode.
vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_TIME, function (error) {
if (error) {
console.log('error.code' + error.code + 'error.message' + error.message); console.log('error.code' + error.code + 'error.message' + error.message);
}else{ return;
console.log('Callback returned to indicate successful.');
} }
console.log('Callback returned to indicate successful.');
}) })
} catch(err) { } catch (err) {
console.info('errCode: ' + err.code + ' ,msg: ' + err.message); console.info('errCode: ' + err.code + ' ,msg: ' + err.message);
} }
``` ```
...@@ -149,7 +169,7 @@ try { ...@@ -149,7 +169,7 @@ try {
stopVibration(stopMode: VibratorStopMode): Promise&lt;void&gt; stopVibration(stopMode: VibratorStopMode): Promise&lt;void&gt;
Stops the vibration with the specified **stopMode**. This API uses a promise to return the result. If the specified **stopMode** is different from the mode used to trigger the vibration, this API fails to be called. Stops vibration in the specified mode. This API uses a promise to return the result.
**Required permissions**: ohos.permission.VIBRATE **Required permissions**: ohos.permission.VIBRATE
...@@ -171,25 +191,43 @@ Stops the vibration with the specified **stopMode**. This API uses a promise to ...@@ -171,25 +191,43 @@ Stops the vibration with the specified **stopMode**. This API uses a promise to
```js ```js
try { try {
vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(()=>{ // Start vibration at a fixed duration.
console.log('Promise returned to indicate a successful vibration.'); vibrator.startVibration({
}, (error)=>{ type: 'time',
duration: 1000
}, {
id: 0,
usage: 'alarm'
}).then(() => {
console.log('Promise returned to indicate a successful vibration');
}, (error) => {
console.error('error.code' + error.code + 'error.message' + error.message);
});
} catch (err) {
console.error('errCode: ' + err.code + ' ,msg: ' + err.message);
}
try {
// Stop vibration in VIBRATOR_STOP_MODE_TIME mode.
vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(() => {
console.log('Promise returned to indicate a successful vibration.');
}, (error) => {
console.log('error.code' + error.code + 'error.message' + error.message); console.log('error.code' + error.code + 'error.message' + error.message);
}); });
} catch(err) { } catch (err) {
console.info('errCode: ' + err.code + ' ,msg: ' + err.message); console.info('errCode: ' + err.code + ' ,msg: ' + err.message);
} }
``` ```
## EffectId ## EffectId
Describes the vibration effect ID. Describes the preset vibration effect ID.
**System capability**: SystemCapability.Sensors.MiscDevice **System capability**: SystemCapability.Sensors.MiscDevice
| Name | Default Value | Description | | Name | Value | Description |
| ------------------ | -------------------- | ------------------ | | ------------------ | -------------------- | -------------------------------- |
| EFFECT_CLOCK_TIMER | "haptic.clock.timer" | Preset vibration effect ID.| | EFFECT_CLOCK_TIMER | "haptic.clock.timer" | Vibration effect of the vibrator when a user adjusts the timer.|
## VibratorStopMode ## VibratorStopMode
...@@ -198,10 +236,10 @@ Enumerates the modes available to stop the vibration. ...@@ -198,10 +236,10 @@ Enumerates the modes available to stop the vibration.
**System capability**: SystemCapability.Sensors.MiscDevice **System capability**: SystemCapability.Sensors.MiscDevice
| Name | Default Value | Description | | Name | Value | Description |
| ------------------------- | -------- | ------------------------------------------------------------ | | ------------------------- | -------- | ------------------------------ |
| VIBRATOR_STOP_MODE_TIME | "time" | The vibration to stop is in **duration** mode. This vibration is triggered with the parameter **duration** of the **number** type.| | VIBRATOR_STOP_MODE_TIME | "time" | The vibration to stop is in **duration** mode.|
| VIBRATOR_STOP_MODE_PRESET | "preset" | The vibration to stop is in **EffectId** mode. This vibration is triggered with the parameter **effectId** of the **EffectId** type.| | VIBRATOR_STOP_MODE_PRESET | "preset" | The vibration to stop is in **EffectId** mode.|
## VibrateEffect<sup>9+</sup> ## VibrateEffect<sup>9+</sup>
...@@ -220,7 +258,7 @@ Describes the vibration with the specified duration. ...@@ -220,7 +258,7 @@ Describes the vibration with the specified duration.
**System capability**: SystemCapability.Sensors.MiscDevice **System capability**: SystemCapability.Sensors.MiscDevice
| Name | Default Value| Description | | Name | Value| Description |
| -------- | ------ | ------------------------------ | | -------- | ------ | ------------------------------ |
| type | "time" | Vibration with the specified duration.| | type | "time" | Vibration with the specified duration.|
| duration | - | Vibration duration, in ms. | | duration | - | Vibration duration, in ms. |
...@@ -231,7 +269,7 @@ Describes the vibration with a preset effect. ...@@ -231,7 +269,7 @@ Describes the vibration with a preset effect.
**System capability**: SystemCapability.Sensors.MiscDevice **System capability**: SystemCapability.Sensors.MiscDevice
| Name | Default Value | Description | | Name | Value | Description |
| -------- | -------- | ------------------------------ | | -------- | -------- | ------------------------------ |
| type | "preset" | Vibration with the specified effect.| | type | "preset" | Vibration with the specified effect.|
| effectId | - | Preset vibration effect ID. | | effectId | - | Preset vibration effect ID. |
...@@ -243,7 +281,7 @@ Describes the vibration attribute. ...@@ -243,7 +281,7 @@ Describes the vibration attribute.
**System capability**: SystemCapability.Sensors.MiscDevice **System capability**: SystemCapability.Sensors.MiscDevice
| Name | Default Value| Description | | Name | Value| Description |
| ----- | ------ | -------------- | | ----- | ------ | -------------- |
| id | 0 | Vibrator ID. | | id | 0 | Vibrator ID. |
| usage | - | Vibration scenario.| | usage | - | Vibration scenario.|
...@@ -293,9 +331,9 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta ...@@ -293,9 +331,9 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta
**Example** **Example**
```js ```js
vibrator.vibrate(1000).then(()=>{ vibrator.vibrate(1000).then(() => {
console.log('Promise returned to indicate a successful vibration.'); console.log('Promise returned to indicate a successful vibration.');
}, (error)=>{ }, (error) => {
console.log('error.code' + error.code + 'error.message' + error.message); console.log('error.code' + error.code + 'error.message' + error.message);
}); });
``` ```
...@@ -317,15 +355,15 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta ...@@ -317,15 +355,15 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------------------------------------------- | | -------- | ------------------------- | ---- | ---------------------------------------------------------- |
| duration | number | Yes | Vibration duration, in ms. | | duration | number | Yes | Vibration duration, in ms. |
| callback | AsyncCallback&lt;void&gt; | No | Callback used to the result. If the vibration starts, **err** is **undefined**. Otherwise, **err** is an error object.| | callback | AsyncCallback&lt;void&gt; | No | Callback used to return the result. If the vibration starts, **err** is **undefined**; otherwise, **err** is an error object.|
**Example** **Example**
```js ```js
vibrator.vibrate(1000,function(error){ vibrator.vibrate(1000, function (error) {
if(error){ if (error) {
console.log('error.code' + error.code + 'error.message' + error.message); console.log('error.code' + error.code + 'error.message' + error.message);
}else{ } else {
console.log('Callback returned to indicate a successful vibration.'); console.log('Callback returned to indicate a successful vibration.');
} }
}) })
...@@ -359,9 +397,9 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta ...@@ -359,9 +397,9 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta
**Example** **Example**
```js ```js
vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER).then(()=>{ vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER).then(() => {
console.log('Promise returned to indicate a successful vibration.'); console.log('Promise returned to indicate a successful vibration.');
}, (error)=>{ }, (error) => {
console.log('error.code' + error.code + 'error.message' + error.message); console.log('error.code' + error.code + 'error.message' + error.message);
}); });
``` ```
...@@ -384,15 +422,15 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta ...@@ -384,15 +422,15 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------------------------------------------- | | -------- | ------------------------- | ---- | ---------------------------------------------------------- |
| effectId | [EffectId](#effectid) | Yes | Preset vibration effect ID. | | effectId | [EffectId](#effectid) | Yes | Preset vibration effect ID. |
| callback | AsyncCallback&lt;void&gt; | No | Callback used to the result. If the vibration starts, **err** is **undefined**. Otherwise, **err** is an error object.| | callback | AsyncCallback&lt;void&gt; | No | Callback used to return the result. If the vibration starts, **err** is **undefined**; otherwise, **err** is an error object.|
**Example** **Example**
```js ```js
vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function(error){ vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function (error) {
if(error){ if (error) {
console.log('error.code' + error.code + 'error.message' + error.message); console.log('error.code' + error.code + 'error.message' + error.message);
}else{ } else {
console.log('Callback returned to indicate a successful vibration.'); console.log('Callback returned to indicate a successful vibration.');
} }
}) })
...@@ -402,7 +440,7 @@ vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function(error){ ...@@ -402,7 +440,7 @@ vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function(error){
stop(stopMode: VibratorStopMode): Promise&lt;void&gt; stop(stopMode: VibratorStopMode): Promise&lt;void&gt;
Stops the vibration with the specified **stopMode**. This API uses a promise to return the result. If the specified **stopMode** is different from the mode used to trigger the vibration, this API fails to be called. Stops vibration in the specified mode. This API uses a promise to return the result.
This API is deprecated since API version 9. You are advised to use [vibrator.stopVibration](#vibratorstopvibration9-1) instead. This API is deprecated since API version 9. You are advised to use [vibrator.stopVibration](#vibratorstopvibration9-1) instead.
...@@ -425,9 +463,18 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sto ...@@ -425,9 +463,18 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sto
**Example** **Example**
```js ```js
vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(()=>{ // Start vibration based on the specified effect ID.
vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function (error) {
if (error) {
console.log('error.code' + error.code + 'error.message' + error.message);
} else {
console.log('Callback returned to indicate a successful vibration.');
}
})
// Stop vibration in VIBRATOR_STOP_MODE_PRESET mode.
vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(() => {
console.log('Promise returned to indicate a successful vibration.'); console.log('Promise returned to indicate a successful vibration.');
}, (error)=>{ }, (error) => {
console.log('error.code' + error.code + 'error.message' + error.message); console.log('error.code' + error.code + 'error.message' + error.message);
}); });
``` ```
...@@ -437,7 +484,7 @@ vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(()=>{ ...@@ -437,7 +484,7 @@ vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(()=>{
stop(stopMode: VibratorStopMode, callback?: AsyncCallback&lt;void&gt;): void stop(stopMode: VibratorStopMode, callback?: AsyncCallback&lt;void&gt;): void
Stops the vibration with the specified **stopMode**. This API uses a promise to return the result. If the specified **stopMode** is different from the mode used to trigger the vibration, this API fails to be called. Stops vibration in the specified mode. This API uses an asynchronous callback to return the result.
This API is deprecated since API version 9. You are advised to use [vibrator.stopVibration](#vibratorstopvibration9) instead. This API is deprecated since API version 9. You are advised to use [vibrator.stopVibration](#vibratorstopvibration9) instead.
...@@ -450,15 +497,24 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sto ...@@ -450,15 +497,24 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sto
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------------- | ---- | ------------------------------------------------------------ |
| stopMode | [VibratorStopMode](#vibratorstopmode) | Yes | Mode to stop the vibration. | | stopMode | [VibratorStopMode](#vibratorstopmode) | Yes | Mode to stop the vibration. |
| callback | AsyncCallback&lt;void&gt; | No | Callback used to the result. If the vibration stops, **err** is **undefined**. Otherwise, **err** is an error object.| | callback | AsyncCallback&lt;void&gt; | No | Callback used to return the result. If the vibration stops, **err** is **undefined**; otherwise, **err** is an error object.|
**Example** **Example**
```js ```js
vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function(error){ // Start vibration based on the specified effect ID.
if(error){ vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function (error) {
if (error) {
console.log('error.code' + error.code + 'error.message' + error.message);
} else {
console.log('Callback returned to indicate a successful vibration.');
}
})
// Stop vibration in VIBRATOR_STOP_MODE_PRESET mode.
vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function (error) {
if (error) {
console.log('error.code' + error.code + 'error.message' + error.message); console.log('error.code' + error.code + 'error.message' + error.message);
}else{ } else {
console.log('Callback returned to indicate successful.'); console.log('Callback returned to indicate successful.');
} }
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册