• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Vibrator
2
3
4> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
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.
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> - This module requires hardware support and can only be debugged on real devices.
8
9
10## Modules to Import
11
12
13```
14import vibrator from '@system.vibrator';
15```
16
17
18## vibrator.vibrate
19
20vibrate(Object): void
21
22Triggers device vibration.
23
24**System capability**: SystemCapability.Sensors.MiscDevice
25
26**Required permissions**: ohos.permission.VIBRATE (a system permission)
27
28**Parameters**
29
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**.|
33
34**Example**
35
36```
37vibrator.vibrate({
38  mode: 'short',
39  success: function() {
40    console.log('vibrate is successful');
41  },
42  fail: function(data, code) {
43    console.log("vibrate is failed, data: " + data + ", code: " + code);
44  },
45  complete: function() {
46    console.log('vibrate is completed');
47  }
48});
49```
50