提交 fd9d2cee 编写于 作者: G Gloria

Update docs against 10218

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 fe6cc89c
......@@ -13,11 +13,11 @@ The **Vibrator** module provides APIs for triggering or stopping vibration.
import vibrator from '@ohos.vibrator';
```
## vibrator.vibrate
## vibrator.startVibration<sup>9+</sup>
vibrate(duration: number): Promise&lt;void&gt;
startVibration(effect: VibrateEffect, attribute: VibrateAttribute, callback: AsyncCallback&lt;void&gt;): void
Triggers vibration with the specified duration. This API uses a promise to return the result.
Triggers vibration with the specified effect and attribute. This API uses a promise to return the result.
**Required permissions**: ohos.permission.VIBRATE
......@@ -26,28 +26,36 @@ Triggers vibration with the specified duration. This API uses a promise to retur
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ---------------------- |
| duration | number | Yes | Vibration duration, in ms.|
**Return value**
| Type | Description |
| ------------------- | -------------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| --------- | -------------------------------------- | ---- | :--------------------------------------------------------- |
| effect | [VibrateEffect](#vibrateeffect9) | Yes | Vibration effect. |
| 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.|
**Example**
```js
vibrator.vibrate(1000).then(()=>{
console.log("Promise returned to indicate a successful vibration.");
```js
try {
vibrator.startVibration({
type:'time',
duration:1000,
},{
id:0,
usage: 'alarm'
}, (error)=>{
console.log("error.code"+error.code+"error.message"+error.message);
if(error){
console.log('vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message);
}else{
console.log('Callback returned to indicate a successful vibration.');
}
});
```
} catch(err) {
console.info('errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
## vibrator.vibrate<sup>9+</sup>
## vibrator.startVibration<sup>9+</sup>
vibrate(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.
......@@ -58,7 +66,7 @@ Triggers vibration with the specified effect and attribute. This API uses a prom
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | -------------------------------------- | ---- | :------------- |
| --------- | -------------------------------------- | ---- | -------------- |
| effect | [VibrateEffect](#vibrateeffect9) | Yes | Vibration effect.|
| attribute | [VibrateAttribute](#vibrateattribute9) | Yes | Vibration attribute.|
......@@ -70,112 +78,219 @@ Triggers vibration with the specified effect and attribute. This API uses a prom
**Example**
```js
vibrator.vibrate({
```js
try {
vibrator.startVibration({
type: 'time',
duration: 1000
}, {
}, {
id: 0,
usage: 'alarm'
}).then(()=>{
console.log("Promise returned to indicate a successful vibration");
}).catch((error)=>{
console.log("error.code" + error.code + "error.message" + error.message);
})
```
}).then(()=>{
console.log('Promise returned to indicate a successful vibration');
}).catch((error)=>{
console.log('error.code' + error.code + 'error.message' + error.message);
})
} catch(err) {
console.info('errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
## vibrator.vibrate
## vibrator.stopVibration<sup>9+</sup>
vibrate(duration: number, callback?: AsyncCallback&lt;void&gt;): void
stopVibration(stopMode: VibratorStopMode, callback: AsyncCallback&lt;void&gt;): void
Triggers vibration with the specified duration. This API uses an asynchronous callback to return the result.
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.
**Required permissions**: ohos.permission.VIBRATE
**System capability**: SystemCapability.Sensors.MiscDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------------------------------------------- |
| 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.|
| -------- | ------------------------------------- | ---- | ------------------------------------------------------------ |
| 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.|
**Example**
```js
vibrator.vibrate(1000,function(error){
try {
vibrator.stopVibration(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{
console.log("Callback returned to indicate a successful vibration.");
console.log('Callback returned to indicate successful.');
}
})
} catch(err) {
console.info('errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
## vibrator.stopVibration<sup>9+</sup>
## vibrator.vibrate
vibrate(effectId: EffectId): Promise&lt;void&gt;
stopVibration(stopMode: VibratorStopMode): Promise&lt;void&gt;
Triggers vibration with the specified effect. This API uses a promise to return the result.
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.
**Required permissions**: ohos.permission.VIBRATE
**System capability**: SystemCapability.Sensors.MiscDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------ |
| effectId | [EffectId](#effectid) | Yes | Preset vibration effect ID.|
| -------- | ------------------------------------- | ---- | ------------------------ |
| stopMode | [VibratorStopMode](#vibratorstopmode) | Yes | Mode to stop the vibration.|
**Return value**
| Type | Description |
| ------------------- | -------------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER).then(()=>{
console.log("Promise returned to indicate a successful vibration.");
try {
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) {
console.info('errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
## EffectId
## vibrator.vibrate
Describes the vibration effect ID.
vibrate(effectId: EffectId, callback?: AsyncCallback&lt;void&gt;): void
**System capability**: SystemCapability.Sensors.MiscDevice
Triggers vibration with the specified effect. This API uses an asynchronous callback to return the result.
| Name | Default Value | Description |
| ------------------ | -------------------- | ------------------ |
| EFFECT_CLOCK_TIMER | "haptic.clock.timer" | Preset vibration effect ID.|
## VibratorStopMode
Enumerates the modes available to stop the vibration.
**System capability**: SystemCapability.Sensors.MiscDevice
| Name | Default 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_PRESET | "preset" | The vibration to stop is in **EffectId** mode. This vibration is triggered with the parameter **effectId** of the **EffectId** type.|
## VibrateEffect<sup>9+</sup>
Describes the vibration effect.
**System capability**: SystemCapability.Sensors.MiscDevice
| Type | Description |
| -------------------------------- | ------------------------------ |
| [VibrateTime](#vibratetime9) | Triggers vibration with the specified duration. This API uses a promise to return the result.|
| [VibratePreset](#vibratepreset9) | Vibration with a preset effect.|
## VibrateTime<sup>9+</sup>
Describes the vibration with the specified duration.
**System capability**: SystemCapability.Sensors.MiscDevice
| Name | Default Value| Description |
| -------- | ------ | ------------------------------ |
| type | "time" | Vibration with the specified duration.|
| duration | - | Vibration duration, in ms. |
## VibratePreset<sup>9+</sup>
Describes the vibration with a preset effect.
**System capability**: SystemCapability.Sensors.MiscDevice
| Name | Default Value | Description |
| -------- | -------- | ------------------------------ |
| type | "preset" | Vibration with the specified effect.|
| effectId | - | Preset vibration effect ID. |
| count | - | Number of vibrations to repeat. |
## VibrateAttribute<sup>9+</sup>
Describes the vibration attribute.
**System capability**: SystemCapability.Sensors.MiscDevice
| Name | Default Value| Description |
| ----- | ------ | -------------- |
| id | 0 | Vibrator ID. |
| usage | - | Vibration scenario.|
## Usage<sup>9+</sup>
Enumerates the vibration scenarios.
**System capability**: SystemCapability.Sensors.MiscDevice
| Name | Type | Description |
| ---------------- | ------ | ------------------------------ |
| unknown | string | Unknown scenario, with the lowest priority.|
| alarm | string | Vibration for alarms. |
| ring | string | Vibration for incoming calls. |
| notification | string | Vibration for notifications. |
| communication | string | Vibration for communication. |
| touch | string | Touch vibration scenario. |
| media | string | Multimedia vibration scenario. |
| physicalFeedback | string | Physical feedback vibration scenario. |
| simulateReality | string | Simulated reality vibration scenario. |
## vibrator.vibrate<sup>(deprecated)</sup>
vibrate(duration: number): Promise&lt;void&gt;
Triggers vibration with the specified duration. This API uses a promise to return the result.
This API is deprecated since API version 9. You are advised to use [vibrator.startVibration](#vibratorstartvibration9-1) instead.
**Required permissions**: ohos.permission.VIBRATE
**System capability**: SystemCapability.Sensors.MiscDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------------------------------------------- |
| 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.|
| -------- | ------ | ---- | ---------------------- |
| duration | number | Yes | Vibration duration, in ms.|
**Return value**
| Type | Description |
| ------------------- | -------------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
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.");
}
})
vibrator.vibrate(1000).then(()=>{
console.log('Promise returned to indicate a successful vibration.');
}, (error)=>{
console.log('error.code' + error.code + 'error.message' + error.message);
});
```
## vibrator.vibrate<sup>9+</sup>
## vibrator.vibrate<sup>(deprecated)</sup>
vibrate(effect: VibrateEffect, attribute: VibrateAttribute, callback: AsyncCallback&lt;void&gt;): void
vibrate(duration: number, callback?: AsyncCallback&lt;void&gt;): void
Triggers vibration with the specified effect and attribute. This API uses an asynchronous callback to return the result.
Triggers vibration with the specified duration. This API uses an asynchronous callback to return the result.
This API is deprecated since API version 9. You are advised to use [vibrator.startVibration](#vibratorstartvibration9) instead.
**Required permissions**: ohos.permission.VIBRATE
......@@ -184,43 +299,40 @@ Triggers vibration with the specified effect and attribute. This API uses an asy
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | -------------------------------------- | ---- | :--------------------------------------------------------- |
| effect | [VibrateEffect](#vibrateeffect9) | Yes | Vibration effect. |
| 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.|
| -------- | ------------------------- | ---- | ---------------------------------------------------------- |
| 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.|
**Example**
```js
vibrator.vibrate({
type:'time',
duration:1000,
},{
id:0,
usage: 'alarm'
}, (error)=>{
```js
vibrator.vibrate(1000,function(error){
if(error){
console.log("vibrate fail, error.code:" + error.code + ",error.message:" + error.message);
console.log('error.code' + error.code + 'error.message' + error.message);
}else{
console.log("Callback returned to indicate a successful vibration.");
console.log('Callback returned to indicate a successful vibration.');
}
});
```
})
```
## vibrator.stop
stop(stopMode: VibratorStopMode): Promise&lt;void&gt;
## vibrator.vibrate<sup>(deprecated)</sup>
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.
vibrate(effectId: EffectId): Promise&lt;void&gt;
Triggers vibration with the specified effect. This API uses a promise to return the result.
This API is deprecated since API version 9. You are advised to use [vibrator.startVibration](#vibratorstartvibration9-1) instead.
**Required permissions**: ohos.permission.VIBRATE
**System capability**: SystemCapability.Sensors.MiscDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ------------------------ |
| stopMode | [VibratorStopMode](#vibratorstopmode) | Yes | Mode to stop the vibration.|
| -------- | --------------------- | ---- | ------------------ |
| effectId | [EffectId](#effectid) | Yes | Preset vibration effect ID.|
**Return value**
......@@ -231,124 +343,107 @@ Stops the vibration with the specified **stopMode**. This API uses a promise to
**Example**
```js
vibrator.stop(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);
});
vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER).then(()=>{
console.log('Promise returned to indicate a successful vibration.');
}, (error)=>{
console.log('error.code' + error.code + 'error.message' + error.message);
});
```
## vibrator.stop
## vibrator.vibrate<sup>(deprecated)</sup>
stop(stopMode: VibratorStopMode, callback?: AsyncCallback&lt;void&gt;): void;
vibrate(effectId: EffectId, callback?: AsyncCallback&lt;void&gt;): void
Triggers vibration with the specified effect. This API uses an asynchronous callback to return the result.
Stops the vibration with the specified **stopMode**. This API uses an asynchronous callback to return the result. If the specified **stopMode** is different from the mode used to trigger the vibration, this API fails to be called.
This API is deprecated since API version 9. You are advised to use [vibrator.startVibration](#vibratorstartvibration9) instead.
**Required permissions**: ohos.permission.VIBRATE
**System capability**: SystemCapability.Sensors.MiscDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ------------------------------------------------------------ |
| 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.|
| -------- | ------------------------- | ---- | ---------------------------------------------------------- |
| 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.|
**Example**
```js
vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function(error){
vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, 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{
console.log("Callback returned to indicate a successful stop.");
console.log('Callback returned to indicate a successful vibration.');
}
})
})
```
## vibrator.stop<sup>(deprecated)</sup>
## EffectId
Describes the vibration effect ID.
**System capability**: SystemCapability.Sensors.MiscDevice
| Name | Default Value | Description |
| ------------------ | -------------------- | ------------------ |
| EFFECT_CLOCK_TIMER | "haptic.clock.timer" | Preset vibration effect ID.|
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.
## VibratorStopMode
This API is deprecated since API version 9. You are advised to use [vibrator.stopVibration](#vibratorstopvibration9-1) instead.
Enumerates the modes available to stop the vibration.
**Required permissions**: ohos.permission.VIBRATE
**System capability**: SystemCapability.Sensors.MiscDevice
| Name | Default 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_PRESET | "preset" | The vibration to stop is in **EffectId** mode. This vibration is triggered with the parameter **effectId** of the **EffectId** type.|
## VibrateEffect<sup>9+</sup>
**Parameters**
Describes the vibration effect.
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ------------------------ |
| stopMode | [VibratorStopMode](#vibratorstopmode) | Yes | Mode to stop the vibration.|
**System capability**: SystemCapability.Sensors.MiscDevice
**Return value**
| Type | Description |
| -------------------------------- | ------------------------------ |
| [VibrateTime](#vibratetime9) | Triggers vibration with the specified duration. This API uses a promise to return the result.|
| [VibratePreset](#vibratepreset9) | Vibration with a preset effect.|
## VibrateTime<sup>9+</sup>
Describes the vibration with the specified duration.
| ------------------- | -------------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**System capability**: SystemCapability.Sensors.MiscDevice
**Example**
| Name | Default Value| Description |
| -------- | ------ | ------------------------------ |
| type | "time" | Vibration with the specified duration.|
| duration | - | Vibration duration, in ms. |
```js
vibrator.stop(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);
});
```
## VibratePreset<sup>9+</sup>
Describes the vibration with a preset effect.
## vibrator.stop<sup>(deprecated)</sup>
**System capability**: SystemCapability.Sensors.MiscDevice
stop(stopMode: VibratorStopMode, callback?: AsyncCallback&lt;void&gt;): void
| Name | Default Value | Description |
| -------- | -------- | ------------------------------ |
| type | "preset" | Vibration with the specified effect.|
| effectId | - | Preset vibration effect ID. |
| count | - | Number of vibrations to repeat. |
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.
## VibrateAttribute<sup>9+</sup>
This API is deprecated since API version 9. You are advised to use [vibrator.stopVibration](#vibratorstopvibration9) instead.
Describes the vibration attribute.
**Required permissions**: ohos.permission.VIBRATE
**System capability**: SystemCapability.Sensors.MiscDevice
| Name | Default Value| Description |
| ----- | ------ | -------------- |
| id | 0 | Vibrator ID. |
| usage | - | Vibration scenario.|
## Usage<sup>9+</sup>
**Parameters**
Enumerates the vibration scenarios.
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ------------------------------------------------------------ |
| 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.|
**System capability**: SystemCapability.Sensors.MiscDevice
**Example**
| Name | Type | Description |
| ---------------- | ------ | ------------------------------ |
| unknown | string | Unknown scenario, with the lowest priority.|
| alarm | string | Vibration for alarms. |
| ring | string | Vibration for incoming calls. |
| notification | string | Vibration for notifications. |
| communication | string | Vibration for communication. |
| touch | string | Touch vibration scenario. |
| media | string | Multimedia vibration scenario. |
| physicalFeedback | string | Physical feedback vibration scenario. |
| simulateReality | string | Simulated reality vibration scenario. |
```js
vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function(error){
if(error){
console.log('error.code' + error.code + 'error.message' + error.message);
}else{
console.log('Callback returned to indicate successful.');
}
})
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册