startVibration参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-vibrator-V5\#vibratorstartvibration9参考代码:src/main/module.json5下添加震动权限"requestPermissions": [ { "name": "ohos.permission.VIBRATE" } ]page.etsimport vibrator from '@ohos.vibrator'; import { BusinessError } from '@ohos.base'; @Entry @Component export struct TestLongPressVibrationPage { @State color: Color = Color.Red flag: boolean = true; build() { Column() { Text('震动') .backgroundColor(this.color) .margin({top:200}) .onClick(() => { this.color = Color.Blue vibrator.startVibration({ type: 'time', duration: 100, }, { id: 0, usage: 'touch' }, (error: BusinessError) => {}) }) } .width('100%') .height('100%') .gesture( GestureGroup(GestureMode.Exclusive, LongPressGesture({ repeat: true }) .onAction((event?: GestureEvent) => { console.info(`ah_长按`); if (event && event.repeat) { console.info(`ah_长按判断`); vibrator.startVibration({ type: 'time', duration: 100, }, { id: 0, usage: 'touch' }).then(()=>{ }); } }))) } }
startVibration
参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-vibrator-V5\#vibratorstartvibration9参考代码: