From 11a1df031684423c4564434404e61bfa1851df60 Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Thu, 2 Mar 2023 07:54:36 +0000 Subject: [PATCH] add interface of isSupportEffect&startVibration Signed-off-by: wuzhihuitmac Change-Id: Id8c56a9b907a6f47e9e785a32617688cbc06f621 --- .../device/vibrator-guidelines.md | 55 +++++++++++++++++++ .../reference/apis/js-apis-vibrator.md | 4 +- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/zh-cn/application-dev/device/vibrator-guidelines.md b/zh-cn/application-dev/device/vibrator-guidelines.md index 553d16fc0d..18bb41045a 100644 --- a/zh-cn/application-dev/device/vibrator-guidelines.md +++ b/zh-cn/application-dev/device/vibrator-guidelines.md @@ -16,6 +16,10 @@ | ohos.vibrator | startVibration(effect: VibrateEffect, attribute: VibrateAttribute, callback: AsyncCallback<void>): void | 根据指定振动效果和振动属性触发马达振动,使用Callback异步回调。 | | ohos.vibrator | stopVibration(stopMode: VibratorStopMode): Promise<void> | 按照指定模式停止马达的振动。 | | ohos.vibrator | stopVibration(stopMode: VibratorStopMode, callback: AsyncCallback<void>): void | 按照指定模式停止马达的振动。 | +| ohos.vibrator | stopVibration(callback: AsyncCallback<void>): void | 停止所有模式的马达振动。 | +| ohos.vibrator | stopVibration(): Promise<void> | 停止所有模式的马达振动。 | +| ohos.vibrator | isSupportEffect(effectId: string, callback: AsyncCallback<boolean>): void | 查询是否支持传入的参数effectId。 | +| ohos.vibrator | isSupportEffect(effectId: string): Promise<void> | 查询是否支持传入的参数effectId。 | ## 开发步骤 @@ -63,6 +67,57 @@ } ``` +4. 停止所有模式的马达振动。 + + ```js + import vibrator from '@ohos.vibrator'; + try { + // 停止所有模式的马达振动 + vibrator.stopVibration(function (error) { + if (error) { + console.log('error.code' + error.code + 'error.message' + error.message); + return; + } + console.log('Callback returned to indicate successful.'); + }) + } catch (error) { + console.info('errCode: ' + error.code + ' ,msg: ' + error.message); + } + ``` + +5. 查询是否支持传入的参数effectId。 + + ```js + import vibrator from '@ohos.vibrator'; + try { + // 查询是否支持'haptic.clock.timer' + vibrator.isSupportEffect('haptic.clock.timer', function (state) { + console.log('The effectId is ' + (state ? 'supported' : 'unsupported')); + if (state) { + try { + vibrator.startVibration({ + type: 'preset', + effectId: 'haptic.clock.timer', + count: 1, + }, { + usage: 'unknown' + }, (error) => { + if(error) { + console.log('haptic.clock.timer vibrator error'); + } else { + console.log('haptic.clock.timer vibrator success'); + } + }); + } catch (error) { + console.error('errCode: ' + error.code + ' ,msg: ' + error.message); + } + } + }) + } catch (error) { + console.error('exception in, error:' + JSON.stringify(error)); + } + ``` + ## 相关实例 diff --git a/zh-cn/application-dev/reference/apis/js-apis-vibrator.md b/zh-cn/application-dev/reference/apis/js-apis-vibrator.md index 2824c25a5b..1be2b14c37 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-vibrator.md +++ b/zh-cn/application-dev/reference/apis/js-apis-vibrator.md @@ -351,9 +351,9 @@ try { usage: 'unknown' }, (error) => { if(error) { - console.log('VibrateTest003 vibrator error'); + console.log('haptic.clock.timer vibrator error'); } else { - console.log('VibrateTest003 vibrator success'); + console.log('haptic.clock.timer vibrator success'); } }); } catch (error) { -- GitLab