You need to sign in or sign up before continuing.
js-apis-system-vibrate.md 1.3 KB
Newer Older
1 2 3 4 5
# Vibrator


> ![icon-note.gif](public_sys-resources/icon-note.gif) **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.
W
wusongqing 已提交
6
> - 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.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
> - This module requires hardware support and can only be debugged on real devices.


## Modules to Import


```
import vibrator from '@system.vibrator';
```


## vibrator.vibrate

vibrate(Object): void

Triggers device vibration.

**System capability**: SystemCapability.Sensors.MiscDevice

**Required permissions**: ohos.permission.VIBRATE (a system permission)

**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**.|

**Example**

```
vibrator.vibrate({
  mode: 'short',
W
wusongqing 已提交
39
  success: function() {
40 41
    console.log('vibrate is successful');
  },
W
wusongqing 已提交
42 43
  fail: function(data, code) {
    console.log("vibrate is failed, data: " + data + ", code: " + code);
44
  },
W
wusongqing 已提交
45
  complete: function() {
46 47 48 49
    console.log('vibrate is completed');
  }
});
```