Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
1a006fb4
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
1a006fb4
编写于
3月 07, 2023
作者:
O
openharmony_ci
提交者:
Gitee
3月 07, 2023
浏览文件
操作
浏览文件
下载
差异文件
!15402 add interface of isSupportEffect&startVibration
Merge pull request !15402 from 17349030869/wzh0301
上级
e98b5f51
a2bcc539
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
381 addition
and
2 deletion
+381
-2
zh-cn/application-dev/device/vibrator-guidelines.md
zh-cn/application-dev/device/vibrator-guidelines.md
+75
-2
zh-cn/application-dev/reference/apis/js-apis-vibrator.md
zh-cn/application-dev/reference/apis/js-apis-vibrator.md
+211
-0
zh-cn/release-notes/changelogs/OpenHarmony_4.0.5.2/changelogs-miscdevice.md
...s/changelogs/OpenHarmony_4.0.5.2/changelogs-miscdevice.md
+95
-0
未找到文件。
zh-cn/application-dev/device/vibrator-guidelines.md
浏览文件 @
1a006fb4
...
...
@@ -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(): Promise
<
void
>
| 停止所有模式的马达振动。 |
| ohos.vibrator | stopVibration(callback: AsyncCallback
<
void
>
): void | 停止所有模式的马达振动。 |
| ohos.vibrator | isSupportEffect(effectId: string): Promise
<
boolean
>
| 查询是否支持传入的参数effectId。返回true则表示支持,否则不支持 |
| ohos.vibrator | isSupportEffect(effectId: string, callback: AsyncCallback
<
boolean
>
): void | 查询是否支持传入的参数effectId。返回true则表示支持,否则不支持 |
## 开发步骤
...
...
@@ -27,7 +31,7 @@
```
js
import
vibrator
from
'
@ohos.vibrator
'
;
try
{
vibrator
.
startVibration
({
vibrator
.
startVibration
({
// 使用startVibration需要添加ohos.permission.VIBRATE权限
type
:
'
time
'
,
duration
:
1000
,
},
{
...
...
@@ -50,7 +54,7 @@
```
js
import
vibrator
from
'
@ohos.vibrator
'
;
try
{
// 按照VIBRATOR_STOP_MODE_TIME模式停止振动
// 按照VIBRATOR_STOP_MODE_TIME模式停止振动
, 使用stopVibration需要添加ohos.permission.VIBRATE权限
vibrator
.
stopVibration
(
vibrator
.
VibratorStopMode
.
VIBRATOR_STOP_MODE_TIME
,
function
(
error
)
{
if
(
error
)
{
console
.
log
(
'
error.code
'
+
error
.
code
+
'
error.message
'
+
error
.
message
);
...
...
@@ -63,6 +67,75 @@
}
```
4.
停止所有模式的马达振动。
```
js
import
vibrator
from
'
@ohos.vibrator
'
;
// 使用startVibration、stopVibration需要添加ohos.permission.VIBRATE权限
try
{
vibrator
.
startVibration
({
type
:
'
time
'
,
duration
:
1000
,
},
{
id
:
0
,
usage
:
'
alarm
'
},
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
'
vibrate fail, error.code:
'
+
error
.
code
+
'
error.message:
'
,
+
error
.
message
);
return
;
}
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
);
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
(
err
,
state
)
{
if
(
err
)
{
console
.
error
(
'
isSupportEffect failed, error:
'
+
JSON
.
stringify
(
err
));
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
));
}
}
})
}
catch
(
error
)
{
console
.
error
(
'
Exception in, error:
'
+
JSON
.
stringify
(
error
));
}
```
## 相关实例
...
...
zh-cn/application-dev/reference/apis/js-apis-vibrator.md
浏览文件 @
1a006fb4
...
...
@@ -42,6 +42,7 @@ startVibration(effect: VibrateEffect, attribute: VibrateAttribute, callback: Asy
示例:
```
js
import
vibrator
from
'
@ohos.vibrator
'
;
try
{
vibrator
.
startVibration
({
type
:
'
time
'
,
...
...
@@ -95,6 +96,7 @@ startVibration(effect: VibrateEffect, attribute: VibrateAttribute): Promise<v
**示例:**
```
js
import
vibrator
from
'
@ohos.vibrator
'
;
try
{
vibrator
.
startVibration
({
type
:
'
time
'
,
...
...
@@ -132,6 +134,7 @@ stopVibration(stopMode: VibratorStopMode, callback: AsyncCallback<void>):
**示例:**
```
js
import
vibrator
from
'
@ohos.vibrator
'
;
try
{
// 按照固定时长振动
vibrator
.
startVibration
({
...
...
@@ -190,6 +193,7 @@ stopVibration(stopMode: VibratorStopMode): Promise<void>
**示例:**
```
js
import
vibrator
from
'
@ohos.vibrator
'
;
try
{
// 按照固定时长振动
vibrator
.
startVibration
({
...
...
@@ -219,6 +223,213 @@ try {
}
```
## vibrator.stopVibration<sup>10+</sup>
stopVibration(callback: AsyncCallback
<
void
>
): void
停止所有模式的马达振动。
**需要权限**
:ohos.permission.VIBRATE
**系统能力**
:SystemCapability.Sensors.MiscDevice
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。当马达停止振动成功,err为undefined,否则为错误对象。 |
**示例:**
```
js
import
vibrator
from
'
@ohos.vibrator
'
;
try
{
// 按照固定时长振动
vibrator
.
startVibration
({
type
:
'
time
'
,
duration
:
1000
,
},
{
id
:
0
,
usage
:
'
alarm
'
},
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
'
vibrate fail, error.code:
'
+
error
.
code
+
'
error.message:
'
,
+
error
.
message
);
return
;
}
console
.
log
(
'
Callback returned to indicate a successful vibration.
'
);
});
}
catch
(
error
)
{
console
.
error
(
'
errCode:
'
+
error
.
code
+
'
,msg:
'
+
error
.
message
);
}
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
);
}
```
## vibrator.stopVibration<sup>10+</sup>
stopVibration(): Promise
<
void
>
停止所有模式的马达振动。
**需要权限**
:ohos.permission.VIBRATE
**系统能力**
:SystemCapability.Sensors.MiscDevice
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------- |
| Promise
<
void
>
| Promise对象。 |
**示例:**
```
js
import
vibrator
from
'
@ohos.vibrator
'
;
try
{
// 按照固定时长振动
vibrator
.
startVibration
({
type
:
'
time
'
,
duration
:
1000
},
{
id
:
0
,
usage
:
'
alarm
'
}).
then
(()
=>
{
console
.
log
(
'
Promise returned to indicate a successful vibration
'
);
},
(
error
)
=>
{
console
.
error
(
'
error.code
'
+
error
.
code
+
'
error.message
'
+
error
.
message
);
});
}
catch
(
error
)
{
console
.
error
(
'
errCode:
'
+
error
.
code
+
'
,msg:
'
+
error
.
message
);
}
try
{
// 停止所有模式的马达振动
vibrator
.
stopVibration
().
then
(()
=>
{
console
.
log
(
'
Promise returned to indicate a successful vibration.
'
);
},
(
error
)
=>
{
console
.
log
(
'
error.code
'
+
error
.
code
+
'
error.message
'
+
error
.
message
);
});
}
catch
(
error
)
{
console
.
info
(
'
errCode:
'
+
error
.
code
+
'
,msg:
'
+
error
.
message
);
}
```
## vibrator.isSupportEffect<sup>10+</sup>
isSupportEffect(effectId: string, callback: AsyncCallback
<
boolean
>
): void
查询是否支持传入的参数effectId。
**系统能力**
:SystemCapability.Sensors.MiscDevice
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | ------------------------------------------------------ |
| effectId | string | 是 | 振动效果id |
| callback | AsyncCallback
<
boolean
>
| 是 | 回调函数。当返回true则表示支持该effectId,否则不支持。 |
**示例:**
```
js
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
));
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
));
}
}
})
}
catch
(
error
)
{
console
.
error
(
'
Exception in, error:
'
+
JSON
.
stringify
(
error
));
}
```
## vibrator.isSupportEffect<sup>10+</sup>
isSupportEffect(effectId: string): Promise
<
boolean
>
查询是否支持传入的参数effectId。
**系统能力**
:SystemCapability.Sensors.MiscDevice
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------ |
| effectId | string | 是 | 振动效果id。 |
**返回值:**
| 类型 | 说明 |
| ---------------------- | --------------------------------------------------------- |
| Promise
<
boolean
>
| Promise对象。当返回true则表示支持该effectId,否则不支持。 |
**示例:**
```
js
import
vibrator
from
'
@ohos.vibrator
'
;
try
{
// 查询是否支持'haptic.clock.timer'
vibrator
.
isSupportEffect
(
'
haptic.clock.timer
'
).
then
((
state
)
=>
{
console
.
log
(
'
The effectId is
'
+
(
state
?
'
supported
'
:
'
unsupported
'
));
if
(
state
)
{
try
{
vibrator
.
startVibration
({
type
:
'
preset
'
,
effectId
:
'
haptic.clock.timer
'
,
count
:
1
,
},
{
usage
:
'
unknown
'
}).
then
(()
=>
{
console
.
log
(
'
Promise returned to indicate a successful vibration
'
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
Promise returned to indicate a failed vibration:
'
+
JSON
.
stringify
(
error
));
});
}
catch
(
error
)
{
console
.
error
(
'
exception in, error:
'
+
JSON
.
stringify
(
error
));
}
}
},
(
error
)
=>
{
console
.
error
(
'
isSupportEffect failed, error:
'
+
JSON
.
stringify
(
error
));
})
}
catch
(
error
)
{
console
.
error
(
'
Exception in, error:
'
+
JSON
.
stringify
(
error
));
}
```
## EffectId
预置的振动效果。
...
...
zh-cn/release-notes/changelogs/OpenHarmony_4.0.5.2/changelogs-miscdevice.md
0 → 100755
浏览文件 @
1a006fb4
# 泛Sensor子系统Changelog
## cl.vibrator.isSupportEffect接口新增
新增isSupportEffect接口。
**变更影响**
基于OpenHarmony4.0.5.2及之后的SDK版本开发的应用,可使用isSupportEffect接口查询传入effectId是否支持。
**关键接口/组件变更**
@ohos.vibrator.d.ts中新增isSupportEffect接口。
| 模块名 | 类名 | 方法/属性/枚举/常量 | 变更类型 |
| -- | -- | -- | -- |
| @ohos.vibrator.d.ts | vibrator | isSupportEffect(effectId: string, callback: AsyncCallback
<
boolean
>
): void | 新增 |
| @ohos.vibrator.d.ts | vibrator | isSupportEffect(effectId: string): Promise
<
boolean
>
| 新增 |
**适配指导**
<br>
通过调用isSupportEffect接口查询是否支持传入的参数effectId。
```
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
));
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
));
}
}
})
}
catch
(
error
)
{
console
.
error
(
'
Exception in, error:
'
+
JSON
.
stringify
(
error
));
}
```
## cl.vibrator.stopVibration接口新增
新增stopVibration接口。
**变更影响**
基于OpenHarmony4.0.5.2及之后的SDK版本开发的应用,可使用stopVibration接口停止所有类型的振动。
**关键接口/组件变更**
@ohos.vibrator.d.ts中新增stopVibration接口。
| 模块名 | 类名 | 方法/属性/枚举/常量 | 变更类型 |
| ------------------- | -------- | -------------------------------------------------------- | -------- |
| @ohos.vibrator.d.ts | vibrator | stopVibration(callback: AsyncCallback
<
void
>
): void | 新增 |
| @ohos.vibrator.d.ts | vibrator | stopVibration(): Promise
<
void
>
| 新增 |
**适配指导**
<br>
通过调用stopVibration接口停止所有类型的振动。
```
ts
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
);
}
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录