提交 b9456040 编写于 作者: W wuzhihuitmac

add interface of isSupportEffect&startVibration

Signed-off-by: Nwuzhihuitmac <wuzhihui4@huawei.com>
Change-Id: I76ec51fe9cfbd959c323f84e13496b177b373ea9
上级 bdc642ea
......@@ -16,10 +16,10 @@
| ohos.vibrator | startVibration(effect: VibrateEffect, attribute: VibrateAttribute, callback: AsyncCallback&lt;void&gt;): void | 根据指定振动效果和振动属性触发马达振动,使用Callback异步回调。 |
| ohos.vibrator | stopVibration(stopMode: VibratorStopMode): Promise&lt;void&gt; | 按照指定模式停止马达的振动。 |
| ohos.vibrator | stopVibration(stopMode: VibratorStopMode, callback: AsyncCallback&lt;void&gt;): void | 按照指定模式停止马达的振动。 |
| ohos.vibrator | stopVibration(callback: AsyncCallback&lt;void&gt;): void | 停止所有模式的马达振动。 |
| ohos.vibrator | stopVibration(): Promise&lt;void&gt; | 停止所有模式的马达振动。 |
| ohos.vibrator | isSupportEffect(effectId: string, callback: AsyncCallback&lt;boolean&gt;): void | 查询是否支持传入的参数effectId。返回true则表示支持,否则不支持 |
| ohos.vibrator | stopVibration(callback: AsyncCallback&lt;void&gt;): void | 停止所有模式的马达振动。 |
| ohos.vibrator | isSupportEffect(effectId: string): Promise&lt;boolean&gt; | 查询是否支持传入的参数effectId。返回true则表示支持,否则不支持 |
| ohos.vibrator | isSupportEffect(effectId: string, callback: AsyncCallback&lt;boolean&gt;): void | 查询是否支持传入的参数effectId。返回true则表示支持,否则不支持 |
## 开发步骤
......@@ -86,7 +86,7 @@
}
console.log('Callback returned to indicate a successful vibration.');
});
// 停止所有模式的马达振动
// 停止所有类型的马达振动
vibrator.stopVibration(function (error) {
if (error) {
console.log('error.code' + error.code + 'error.message' + error.message);
......
......@@ -403,15 +403,11 @@ isSupportEffect(effectId: string): Promise&lt;boolean&gt;
import vibrator from '@ohos.vibrator';
try {
// 查询是否支持'haptic.clock.timer'
vibrator.isSupportEffect('haptic.clock.timer').then((err, state) => {
if (err) {
console.error('isSupportEffect failed. Error msg:' + JSON.stringify(err));
return;
}
vibrator.isSupportEffect('haptic.clock.timer').then((state) => {
console.log('The effectId is ' + (state ? 'supported' : 'unsupported'));
if (state) {
try {
vibrator.startVibration({ // 使用startVibration需要ohos.permission.VIBRATE权限
vibrator.startVibration({
type: 'preset',
effectId: 'haptic.clock.timer',
count: 1,
......
......@@ -6,7 +6,7 @@
**变更影响**
基于OpenHarmony4.0.5.2及之后的SDK版本开发的应用,可使用isSupportEffect接口查询传入effectId是否支持;使用stopVibration接口停止所有类型的振动的
基于OpenHarmony4.0.5.2及之后的SDK版本开发的应用,可使用isSupportEffect接口查询传入effectId是否支持。
**关键接口/组件变更**
......@@ -62,7 +62,7 @@ try {
**变更影响**
基于OpenHarmony4.0.5.2及之后的SDK版本开发的应用,可使用stopVibration接口停止所有类型的振动
基于OpenHarmony4.0.5.2及之后的SDK版本开发的应用,可使用stopVibration接口停止所有类型的振动。
**关键接口/组件变更**
......@@ -75,40 +75,21 @@ try {
**适配指导**<br>
通过调用isSupportEffect接口查询是否支持传入的参数effectId
通过调用stopVibration接口停止所有类型的振动
```ts
import vibrator from '@ohos.vibrator';
try {
// 查询是否支持'haptic.clock.timer'
vibrator.isSupportEffect('haptic.clock.timer', function (err, state) {
if (err) {
console.error('isSupportEffect failed, error:' + JSON.stringify(err));
// 停止所有模式的马达振动
vibrator.stopVibration(function (error) {
if (error) {
console.log('error.code' + error.code + 'error.message' + error.message);
return;
}
console.log('The effectId is ' + (state ? 'supported' : 'unsupported'));
if (state) {
try {
vibrator.startVibration({ // 使用startVibration需要添加ohos.permission.VIBRATE权限
type: 'preset',
effectId: 'haptic.clock.timer',
count: 1,
}, {
usage: 'unknown'
}, (error) => {
if(error) {
console.error('haptic.clock.timer vibrator error:' + JSON.stringify(error));
} else {
console.log('haptic.clock.timer vibrator success');
}
});
} catch (error) {
console.error('Exception in, error:' + JSON.stringify(error));
}
}
console.log('Callback returned to indicate successful.');
})
} catch (error) {
console.error('Exception in, error:' + JSON.stringify(error));
console.info('errCode: ' + error.code + ' ,msg: ' + error.message);
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册