同步操作将从 OpenHarmony/docs 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
说明: 从API Version 8 开始支持。
import vibrate from '@ohos.vibrator';
ohos.permission.VIBRATE
vibrate(duration: number): Promise<void>
按照指定持续时间触发马达振动。
参数:
返回值:
示例:
vibrate.vibrate(100).then(()=>
console.log('Promise returned to indicate a successful vibration.')
).catch((error) => {
console.error('Failed to trigger vibration.');
});
vibrate(duration: number, callback?: AsyncCallback<void>): void
按照指定持续时间触发马达振动。
参数:
示例:
vibrate.vibrate(100, function(error) {
if (error) {
console.error("Failed to trigger vibration. Error code: " + error.code + ", message: " + error.message);
return;
}
console.info("Succeeded in triggering vibration.");
});
vibrate(effectId: EffectId): Promise<void>
按照指定振动效果触发马达振动。
参数:
返回值:
示例:
vibrate.vibrate(vibrate.EffectId.EFFECT_CLOCK_TIMER).then(()=>
console.log('Promise returned to indicate a successful vibration.')
).catch((error) => {
console.error('Failed to trigger vibration.');
});
vibrate(effectId: EffectId, callback?: AsyncCallback<void>): void
按照指定振动效果触发马达振动。
参数:
示例:
vibrate.vibrate(vibrate.EffectId.EFFECT_CLOCK_TIMER, function(error) {
if (error) {
console.error("Failed to trigger vibration. Error code: " + error.code + ", message: " + error.message);
return;
}
console.info("Succeeded in triggering vibration.");
});
stop(stopMode: VibratorStopMode): Promise<void>
按照要停止指定的振动模式来停止马达的振动。如果要停止的振动模式与触发马达振动时的模式不相同,则调用本接口会失败。
参数:
返回值:
示例:
vibrate.stop(vibrate.VibratorStopMode.VIBRATOR_STOP_MODE_TIME).then(()=>
console.log('Promise returned to indicate a successful vibration stop.')
).catch((error) => {
console.error('Failed to stop vibration.');
});
stop(stopMode: VibratorStopMode, callback?: AsyncCallback<void>): void;
按照要停止指定的振动模式来停止马达的振动。如果要停止的振动模式与触发马达振动时的模式不相同,则调用本接口会失败。
参数:
示例:
vibrate.stop(vibrate.VibratorStopMode.VIBRATOR_STOP_MODE_TIME, function(error) {
if (error) {
console.error("Failed to stop vibration. Error code: " + error.code + ", message: " + error.message);
return;
}
console.info("Vibration stopped.");
});
表示马达振动效果的字符串。
表示马达要停止指定的振动模式。
停止模式为预置EffectId的振动。即触发振动时参数类型为EffectId,参数本身为指示马达振动效果的字符串的触发方式。 |
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。