diff --git a/zh-cn/application-dev/reference/apis/js-apis-screen-lock.md b/zh-cn/application-dev/reference/apis/js-apis-screen-lock.md index 09b8a7a4c4e1e30ce097702132ea8f02e94227fa..10eff3f3b3fa7b6f8f9772d70ee127bf146f7376 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-screen-lock.md +++ b/zh-cn/application-dev/reference/apis/js-apis-screen-lock.md @@ -20,12 +20,12 @@ isScreenLocked(callback: AsyncCallback<boolean>): void **系统能力**: SystemCapability.MiscServices.ScreenLock -- 参数: +- **参数**: | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | callback | AsyncCallback<boolean> | 是 | 回调函数,返回true表示屏幕已锁屏,返回false表示屏幕未锁屏。 | -- 示例: +- **示例**: ```js screenlock.isScreenLocked((err, data)=>{ @@ -46,12 +46,12 @@ isScreenLocked(): Promise<boolean> **系统能力**: SystemCapability.MiscServices.ScreenLock -- 返回值: +- **返回值**: | 类型 | 说明 | | -------- | -------- | | Promise<boolean> | 以Promise形式返回结果。 | -- 示例: +- **示例**: ```js screenlock.isScreenLocked().then((data) => { @@ -73,12 +73,12 @@ isSecureMode(callback: AsyncCallback<boolean>): void **系统能力**: SystemCapability.MiscServices.ScreenLock -- 参数: +- **参数**: | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示屏幕处于安全模式下,返回false表示屏幕当前不在安全模式下。 | -- 示例: +- **示例**: ```js screenlock.isSecureMode((err, data)=>{ @@ -99,12 +99,12 @@ isSecureMode(): Promise<boolean> **系统能力**: SystemCapability.MiscServices.ScreenLock -- 返回值: +- **返回值**: | 类型 | 说明 | | -------- | -------- | | Promise<boolean> | 以Promise形式返回结果。 | -- 示例: +- **示例**: ```js screenlock.isSecureMode().then((data) => { @@ -126,15 +126,15 @@ unlockScreen(callback: AsyncCallback<void>): void **系统能力**: SystemCapability.MiscServices.ScreenLock -- 参数: +- **参数**: | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | callback | AsyncCallback<void> | 是 | 回调函数,失败时返回错误信息。 | -- 示例: +- **示例**: ```js - screenlock.unlockScreen((err)=>{ + screenlock.unlockScreen((err) => { if (err) { console.error('unlockScreen callback error -> ${JSON.stringify(err)}'); return; @@ -152,12 +152,12 @@ unlockScreen(): Promise<void> **系统能力**: SystemCapability.MiscServices.ScreenLock -- 返回值: +- **返回值**: | 类型 | 说明 | | -------- | -------- | | Promise<void> | 以Promise形式返回结果。 | -- 示例: +- **示例**: ```js screenlock.unlockScreen().then(() => { @@ -166,3 +166,141 @@ unlockScreen(): Promise<void> console.error('unlockScreen fail, promise: err->${JSON.stringify(err)}'); }); ``` + +## screenlock.on9+ + +on(type: 'beginWakeUp' | 'endWakeUp' | 'beginScreenOn' | 'endScreenOn' | 'beginScreenOff' | 'endScreenOff' | 'unlockScreen' | 'beginExitAnimation', callback: Callback\): void + +注册锁屏状态变化回调。 + +**系统能力**: SystemCapability.MiscServices.ScreenLock + +- **参数**: + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | type | string | 是 | 设置事件类型。
- type为"beginWakeUp",表示事件开始时开始唤醒。
- type为"endWakeUp",表示事件结束时结束唤醒。
- type为"beginScreenOn",表示事件开始时开始亮屏。
- type为"endScreenOn",表示事件结束时结束亮屏。
- type为"beginScreenOff",表示事件开始时开始灭屏。
- type为"endScreenOff",表示事件结束时结束灭屏。
- type为"unlockScreen",表示请求解锁。
- type为"beginExitAnimation",表示动画开始退场。 | + | callback | Callback\ | 是 | 事件回调方法。 | + +- **示例**: + + ```js + screenlock.on('beginWakeUp', () => { + console.log('beginWakeUp triggered'); + }); + ``` + +## screenlock.on9+ + +on(type: 'beginSleep' | 'endSleep' | 'changeUser', callback: Callback\): void + +注册锁屏状态变化回调。 + +**系统能力**: SystemCapability.MiscServices.ScreenLock + +- **参数**: + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | type | string | 是 | 设置事件类型。
- type为"beginSleep",表示开始休眠。
- type为"endSleep",表示结束休眠。
- type为"changeUser",表示切换用户。 | + | callback | Callback\ | 是 | 事件回调方法。
返回事件相应的状态。 | + +- **示例**: + + ```js + screenlock.on('beginSleep', (why) => { + console.log('beginSleep triggered:' + why); + }); + ``` +## screenlock.on9+ + +on(type: 'screenlockEnabled', callback: Callback\): void + +注册锁屏状态变化回调。 + +**系统能力**: SystemCapability.MiscServices.ScreenLock + +- **参数**: + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | type | string | 是 | 设置事件类型。
- type为"screenlockEnabled",表示锁屏是否启用。 | + | callback | Callback\ | 是 | 注册成功的回调。
回调结果用true/false表示。 | + +- **示例**: + + ```js + screenlock.on('screenlockEnabled', (isEnabled) => { + console.log('screenlockEnabled triggered, result:' + isEnabled); + }); + ``` + +## screenlock.off9+ + +off(type: 'beginWakeUp' | 'endWakeUp' | 'beginScreenOn' | 'endScreenOn' | 'beginScreenOff' | 'endScreenOff' + | 'unlockScreen' | 'beginExitAnimation' | 'screenlockEnabled' | 'beginSleep' | 'endSleep' | 'changeUser', callback: Callback\): void + +取消注册锁屏状态变化回调。 + +**系统能力**: SystemCapability.MiscServices.ScreenLock + +- **参数**: + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | type | string | 是 | 设置事件类型。
- type为"beginWakeUp",表示事件开始时开始唤醒。
- type为"endWakeUp",表示事件结束时结束唤醒。
- type为"beginScreenOn",表示事件开始时开始亮屏。
- type为"endScreenOn",表示事件结束时结束亮屏。
- type为"beginScreenOff",表示事件开始时开始灭屏。
- type为"endScreenOff",表示事件结束时结束灭屏。
- type为"unlockScreen",表示请求解锁。
- type为"beginExitAnimation",表示动画开始退场。
- type为"screenlockEnabled",表示锁屏是否启用。
- type为"beginSleep",表示开始休眠。
- type为"endSleep",表示结束休眠。
- type为"changeUser",表示切换用户。 | + | callback | Callback\ | 是 | 注册成功的回调。 | + +- **示例**: + + ```js + screenlock.off('beginWakeUp', () => { + console.log("callback"); + }); + ``` + +## screenlock.sendScreenLockEvent9+ + +sendScreenLockEvent(event: String, parameter: number, callback: AsyncCallback\): void + +应用发送事件到锁屏服务,异步方法。 + +**系统能力**: SystemCapability.MiscServices.ScreenLock + +- **参数**: + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | event | String | 是 | 事件类型,支持如下取值:
- "unlockScreenResult",表示解锁结果。
- "screenDrawDone",表示屏幕绘制完成。 | + | parameter | number | 是 | 解锁状态。
- parameter为0,表示解锁成功。
- parameter为1,表示解锁失败。
- parameter为2,表示解锁取消。 | + | callback | AsyncCallback\ | 是 | 表示执行结果。 | + +- **示例**: + + ```js + screenlock.sendScreenLockEvent('unlockScreenResult', 0, (err, result) => { + console.log('sending result:' + result); + }); + ``` + +## screenlock.sendScreenLockEvent9+ + +sendScreenLockEvent(event: String, parameter: number): Promise + +应用发送事件到锁屏服务,异步方法。 + +**系统能力**: SystemCapability.MiscServices.ScreenLock + +- **参数**: + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | event | String | 是 | 事件类型,支持如下取值:
- "unlockScreenResult",表示解锁结果。
- "screenDrawDone",表示屏幕绘制完成。 | + | parameter | number | 是 | 解锁状态。
- parameter为0,表示解锁成功。
- parameter为1,表示解锁失败。
- parameter为2,表示解锁取消。 | + +- **返回值**: + | 类型 | 说明 | + | -------- | -------- | + | Promise\ | 以Promise形式返回执行结果。 | + +- **示例**: + + ```js + screenlock.sendScreenLockEvent('unlockScreenResult', 0).then((err, result) => { + console.log('sending result:' + result); + }); + ```