has.vibrateShort(Object object)
Vibrates a device for a short period of time (15 milliseconds).
Since: 1.0.0
Required permissions: ohos.permission.VIBRATE, which needs to be declared in module.json5
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Vibration intensity type. The value can be heavy, medium, and light. |
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Return value of fail
| Parameter | Type | Description |
|---|---|---|
| errMsg | string | Error message. |
Error code information
| Error Code | Error Message |
|---|---|
| 12000401 | vibrateShort error. For details, see Vibrator Error Codes. |
Example:
has.vibrateShort({
type: 'heavy',
success: (res) => {
console.info('vibrateShort success', res);
},
fail: (err) => {
console.error('vibrateShort fail', err);
},
complete: (res) => {
console.info('vibrateShort complete', res);
}
}); has.vibrateLong(Object object)
Vibrates a device for a long period of time (400 milliseconds).
Since: 1.0.0
Required permissions: ohos.permission.VIBRATE, which needs to be declared in module.json5
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Error code information
| Error Code | Error Message |
|---|---|
| 12000501 | vibrateLong error. For details, see Vibrator Error Codes. |
Example:
has.vibrateLong({
success: () => {
console.info('vibrateLong success');
},
fail: (err) => {
console.error('vibrateLong fail', err);
},
complete: (res) => {
console.info('vibrateLong complete', res);
}
});