1# 泛Sensor子系统Changelog
2
3## cl.vibrator.isSupportEffect接口新增
4
5新增isSupportEffect接口。
6
7**变更影响**
8
9基于OpenHarmony4.0.5.2及之后的SDK版本开发的应用,可使用isSupportEffect接口查询传入effectId是否支持。
10
11**关键接口/组件变更**
12
13@ohos.vibrator.d.ts中新增isSupportEffect接口。
14
15| 模块名 | 类名 | 方法/属性/枚举/常量 | 变更类型 |
16|  -- | -- | -- | -- |
17| @ohos.vibrator.d.ts | vibrator | isSupportEffect(effectId: string, callback: AsyncCallback<boolean>): void | 新增 |
18| @ohos.vibrator.d.ts | vibrator | isSupportEffect(effectId: string): Promise<boolean> | 新增 |
19
20**适配指导**<br>
21
22通过调用isSupportEffect接口查询是否支持传入的参数effectId。
23
24```ts
25import vibrator from '@ohos.vibrator';
26try {
27    // 查询是否支持'haptic.clock.timer'
28    vibrator.isSupportEffect('haptic.clock.timer', function (err, state) {
29        if (err) {
30            console.error('isSupportEffect failed, error:' + JSON.stringify(err));
31            return;
32        }
33        console.log('The effectId is ' + (state ? 'supported' : 'unsupported'));
34        if (state) {
35            try {
36                vibrator.startVibration({ // 使用startVibration需要添加ohos.permission.VIBRATE权限
37                    type: 'preset',
38                    effectId: 'haptic.clock.timer',
39                    count: 1,
40                }, {
41                    usage: 'unknown'
42                }, (error) => {
43                    if(error) {
44                        console.error('haptic.clock.timer vibrator error:'  + JSON.stringify(error));
45                    } else {
46                        console.log('haptic.clock.timer vibrator success');
47                    }
48                });
49            } catch (error) {
50                console.error('Exception in, error:' + JSON.stringify(error));
51            }
52        }
53    })
54} catch (error) {
55    console.error('Exception in, error:' + JSON.stringify(error));
56}
57```
58
59## cl.vibrator.stopVibration接口新增
60
61新增stopVibration接口。
62
63**变更影响**
64
65基于OpenHarmony4.0.5.2及之后的SDK版本开发的应用,可使用stopVibration接口停止所有类型的振动。
66
67**关键接口/组件变更**
68
69@ohos.vibrator.d.ts中新增stopVibration接口。
70
71| 模块名              | 类名     | 方法/属性/枚举/常量                                      | 变更类型 |
72| ------------------- | -------- | -------------------------------------------------------- | -------- |
73| @ohos.vibrator.d.ts | vibrator | stopVibration(callback: AsyncCallback&lt;void&gt;): void | 新增     |
74| @ohos.vibrator.d.ts | vibrator | stopVibration(): Promise&lt;void&gt;                     | 新增     |
75
76**适配指导**<br>
77
78通过调用stopVibration接口停止所有类型的振动。
79
80```ts
81import vibrator from '@ohos.vibrator';
82try {
83    // 停止所有模式的马达振动
84    vibrator.stopVibration(function (error) {
85        if (error) {
86            console.log('error.code' + error.code + 'error.message' + error.message);
87            return;
88        }
89        console.log('Callback returned to indicate successful.');
90    })
91} catch (error) {
92    console.info('errCode: ' + error.code + ' ,msg: ' + error.message);
93}
94```
95
96