js-apis-system-vibrate.md 1.5 KB
Newer Older
1 2 3
# Vibrator


W
wusongqing 已提交
4
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
5
> - 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
> - 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**

W
wusongqing 已提交
30
| Name| Type| Mandatory| Description|
31 32
| -------- | -------- | -------- | -------- |
| mode | string | No| Vibration mode. The value **long** indicates long vibration, and **short** indicates short vibration. The default value is **long**.|
W
wusongqing 已提交
33 34 35
| success | Function | Yes| Called when the vibrator data changes.|
| fail | Function | No| Called when the API call fails.|
| complete | Function | No| Called when the API call is complete.|
36 37 38 39 40 41

**Example**

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