harmony 鸿蒙@system.vibrator (Vibrator)

  • 2022-08-09
  • 浏览 (699)

@system.vibrator (Vibrator)

The Vibrator module provides APIs for controlling LED lights and vibrators. You can use the APIs to query the LED light list, turn on and off the LED light, query the vibrator list, query the vibrator effect, and trigger and turn off the vibrator.

Misc devices refer to LED lights and vibrators on devices. LED lights are mainly used for indication (for example, indicating the charging state) and blinking (such as tri-colored lights). Vibrators are mainly used in scenarios such as the alarm clock, power-on/off, and incoming call vibration.

NOTE - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. - The APIs of this module are no longer maintained since API version 8. You are advised to use @ohos.vibrator instead. - This module requires hardware support and can only be debugged on real devices.

Modules to Import

import vibrator from '@system.vibrator';

vibrator.vibrate

vibrate(options?: VibrateOptions): void

Triggers device vibration.

Required permissions: ohos.permission.VIBRATE

System capability: SystemCapability.Sensors.MiscDevice.Lite

Parameters

Name Type Mandatory Description
options VibrateOptions No Vibration options.

Example

import vibrator from '@system.vibrator';
import { VibrateOptions } from '@system.vibrator';

let vibrateOptions: VibrateOptions = {
  mode: 'short',
  success: () => {
    console.info('Succeed in vibrating');
  },
  fail: (data: string, code: number) => {
    console.info(`Failed to vibrate. Data: ${data}, code: ${code}`);
  },
  complete: () => {
    console.info('completed in vibrating');
  }
};
vibrator.vibrate(vibrateOptions);

VibrateOptions

Defines the vibration options.

Required permissions: ohos.permission.VIBRATE

System capability: SystemCapability.Sensors.MiscDevice.Lite

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.
success Function No 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.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞