“eaeff90edec7fee8dc91ea3b39b53e0378291df7”上不存在“...fluid/eager/api/git@gitcode.net:RobotFutures/Paddle.git”
提交 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. ...@@ -13,11 +13,11 @@ The **Vibrator** module provides APIs for triggering or stopping vibration.
import vibrator from '@ohos.vibrator'; 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 **Required permissions**: ohos.permission.VIBRATE
...@@ -25,29 +25,37 @@ Triggers vibration with the specified duration. This API uses a promise to retur ...@@ -25,29 +25,37 @@ Triggers vibration with the specified duration. This API uses a promise to retur
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ---------------------- | | --------- | -------------------------------------- | ---- | :--------------------------------------------------------- |
| duration | number | Yes | Vibration duration, in ms.| | effect | [VibrateEffect](#vibrateeffect9) | Yes | Vibration effect. |
| attribute | [VibrateAttribute](#vibrateattribute9) | Yes | Vibration attribute. |
**Return value** | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to the result. If the vibration starts, **err** is **undefined**. Otherwise, **err** is an error object.|
| Type | Description |
| ------------------- | -------------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
vibrator.vibrate(1000).then(()=>{ try {
console.log("Promise returned to indicate a successful vibration."); vibrator.startVibration({
}, (error)=>{ type:'time',
console.log("error.code"+error.code+"error.message"+error.message); duration:1000,
}); },{
``` id:0,
usage: 'alarm'
}, (error)=>{
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. 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 ...@@ -58,7 +66,7 @@ Triggers vibration with the specified effect and attribute. This API uses a prom
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | -------------------------------------- | ---- | :------------- | | --------- | -------------------------------------- | ---- | -------------- |
| effect | [VibrateEffect](#vibrateeffect9) | Yes | Vibration effect.| | effect | [VibrateEffect](#vibrateeffect9) | Yes | Vibration effect.|
| attribute | [VibrateAttribute](#vibrateattribute9) | Yes | Vibration attribute.| | attribute | [VibrateAttribute](#vibrateattribute9) | Yes | Vibration attribute.|
...@@ -70,146 +78,60 @@ Triggers vibration with the specified effect and attribute. This API uses a prom ...@@ -70,146 +78,60 @@ Triggers vibration with the specified effect and attribute. This API uses a prom
**Example** **Example**
```js ```js
vibrator.vibrate({ try {
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)=>{ }).catch((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);
## vibrator.vibrate }
vibrate(duration: number, callback?: AsyncCallback&lt;void&gt;): void
Triggers vibration with the specified duration. This API uses an asynchronous callback to return the result.
**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.|
**Example**
```js
vibrator.vibrate(1000,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.stopVibration<sup>9+</sup>
## vibrator.vibrate stopVibration(stopMode: VibratorStopMode, callback: AsyncCallback&lt;void&gt;): void
vibrate(effectId: EffectId): 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.
Triggers vibration with the specified effect. This API uses a promise to return the result.
**Required permissions**: ohos.permission.VIBRATE **Required permissions**: ohos.permission.VIBRATE
**System capability**: SystemCapability.Sensors.MiscDevice **System capability**: SystemCapability.Sensors.MiscDevice
**Parameters** **Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------ |
| effectId | [EffectId](#effectid) | Yes | Preset vibration effect ID.|
**Return value** | Name | Type | Mandatory| Description |
| Type | Description | | -------- | ------------------------------------- | ---- | ------------------------------------------------------------ |
| ------------------- | -------------------------------------- | | stopMode | [VibratorStopMode](#vibratorstopmode) | Yes | Mode to stop the vibration. |
| Promise&lt;void&gt; | Promise that returns no value.| | 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(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.vibrate
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.
**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.|
**Example** **Example**
```js ```js
vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function(error){ try {
if(error){ vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function(error){
console.log("error.code" + error.code + "error.message" + error.message); if(error){
}else{ console.log('error.code' + error.code + 'error.message' + error.message);
console.log("Callback returned to indicate a successful vibration."); }else{
} console.log('Callback returned to indicate successful.');
}) }
})
} catch(err) {
console.info('errCode: ' + err.code + ' ,msg: ' + err.message);
}
``` ```
## vibrator.vibrate<sup>9+</sup> ## vibrator.stopVibration<sup>9+</sup>
vibrate(effect: VibrateEffect, attribute: VibrateAttribute, callback: AsyncCallback&lt;void&gt;): void
Triggers vibration with the specified effect and attribute. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.VIBRATE
**System capability**: SystemCapability.Sensors.MiscDevice stopVibration(stopMode: VibratorStopMode): Promise&lt;void&gt;
**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.|
**Example**
```js
vibrator.vibrate({
type:'time',
duration:1000,
},{
id:0,
usage: 'alarm'
}, (error)=>{
if(error){
console.log("vibrate fail, error.code:" + error.code + ",error.message:" + error.message);
}else{
console.log("Callback returned to indicate a successful vibration.");
}
});
```
## vibrator.stop
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 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.
...@@ -218,6 +140,7 @@ Stops the vibration with the specified **stopMode**. This API uses a promise to ...@@ -218,6 +140,7 @@ Stops the vibration with the specified **stopMode**. This API uses a promise to
**System capability**: SystemCapability.Sensors.MiscDevice **System capability**: SystemCapability.Sensors.MiscDevice
**Parameters** **Parameters**
| 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.|
...@@ -231,43 +154,17 @@ Stops the vibration with the specified **stopMode**. This API uses a promise to ...@@ -231,43 +154,17 @@ Stops the vibration with the specified **stopMode**. This API uses a promise to
**Example** **Example**
```js ```js
vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(()=>{ try {
console.log("Promise returned to indicate a successful vibration."); vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(()=>{
}, (error)=>{ console.log('Promise returned to indicate a successful vibration.');
console.log("error.code" + error.code + "error.message" + error.message); }, (error)=>{
}); console.log('error.code' + error.code + 'error.message' + error.message);
``` });
} catch(err) {
console.info('errCode: ' + err.code + ' ,msg: ' + err.message);
## vibrator.stop }
stop(stopMode: VibratorStopMode, callback?: AsyncCallback&lt;void&gt;): void;
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.
**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.|
**Example**
```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 a successful stop.");
}
})
``` ```
## EffectId ## EffectId
Describes the vibration effect ID. Describes the vibration effect ID.
...@@ -352,3 +249,201 @@ Enumerates the vibration scenarios. ...@@ -352,3 +249,201 @@ Enumerates the vibration scenarios.
| media | string | Multimedia vibration scenario. | | media | string | Multimedia vibration scenario. |
| physicalFeedback | string | Physical feedback vibration scenario. | | physicalFeedback | string | Physical feedback vibration scenario. |
| simulateReality | string | Simulated reality 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 |
| -------- | ------ | ---- | ---------------------- |
| duration | number | Yes | Vibration duration, in ms.|
**Return value**
| Type | Description |
| ------------------- | -------------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
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>(deprecated)</sup>
vibrate(duration: number, callback?: AsyncCallback&lt;void&gt;): void
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
**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.|
**Example**
```js
vibrator.vibrate(1000,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<sup>(deprecated)</sup>
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 |
| -------- | --------------------- | ---- | ------------------ |
| effectId | [EffectId](#effectid) | Yes | Preset vibration effect ID.|
**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.');
}, (error)=>{
console.log('error.code' + error.code + 'error.message' + error.message);
});
```
## vibrator.vibrate<sup>(deprecated)</sup>
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.
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 |
| -------- | ------------------------- | ---- | ---------------------------------------------------------- |
| 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.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.stop<sup>(deprecated)</sup>
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.
This API is deprecated since API version 9. You are advised to use [vibrator.stopVibration](#vibratorstopvibration9-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.|
**Return value**
| Type | Description |
| ------------------- | -------------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**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.stop<sup>(deprecated)</sup>
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.
This API is deprecated since API version 9. You are advised to use [vibrator.stopVibration](#vibratorstopvibration9) 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.|
**Example**
```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.
先完成此消息的编辑!
想要评论请 注册