1# @ohos.screenLock (锁屏管理) 2 3锁屏管理服务是OpenHarmony中的系统服务,为锁屏应用提供注册亮屏、灭屏、开启屏幕、结束休眠、退出动画、请求解锁结果监听,并提供回调结果给锁屏应用。锁屏管理服务向三方应用提供请求解锁、查询锁屏状态、查询是否设置锁屏密码的能力。 4 5> **说明:** 6> 7> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8 9## 导入模块 10 11```ts 12import screenLock from '@ohos.screenLock'; 13``` 14 15## screenLock.isScreenLocked<sup>(deprecated)</sup> 16 17isScreenLocked(callback: AsyncCallback<boolean>): void 18 19判断屏幕是否锁屏。使用callback异步回调。 20 21> **说明:** 22> 23> 从API version 7开始支持,从API version 9开始废弃。 24 25**系统能力:** SystemCapability.MiscServices.ScreenLock 26 27**参数:** 28 29| 参数名 | 类型 | 必填 | 说明 | 30| -------- | ---------------------------- | ---- | ----------------------------------------------------------- | 31| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示屏幕已锁屏;返回false表示屏幕未锁屏。 | 32 33**示例:** 34 35 ```ts 36 import { BusinessError } from '@ohos.base'; 37 38 screenLock.isScreenLocked((err: BusinessError, data: Boolean)=>{ 39 if (err) { 40 console.error(`Failed to obtain whether the screen is locked, Code: ${err.code}, message: ${err.message}`); 41 return; 42 } 43 console.info(`Succeeded in Obtaining whether the screen is locked. result: ${data}`); 44 }); 45 ``` 46 47## screenLock.isScreenLocked<sup>(deprecated)</sup> 48 49isScreenLocked(): Promise<boolean> 50 51判断屏幕是否锁屏。使用Promise异步回调。 52 53> **说明:** 54> 55> 从API version 7开始支持,从API version 9开始废弃。 56 57**系统能力:** SystemCapability.MiscServices.ScreenLock 58 59**返回值:** 60 61| 类型 | 说明 | 62| ---------------------- | ------------------------------------------- | 63| Promise<boolean> | Promise对象。返回true表示屏幕已锁屏;返回false表示屏幕未锁屏。 | 64 65**示例:** 66 67 ```ts 68 import { BusinessError } from '@ohos.base'; 69 70 screenLock.isScreenLocked().then((data: Boolean) => { 71 console.info(`Succeeded in Obtaining whether the screen is locked. result: ${data}`); 72 }).catch((err: BusinessError) => { 73 console.error(`Failed to obtain whether the screen is locked, Code: ${err.code}, message: ${err.message}`); 74 }); 75 ``` 76 77## screenLock.isSecureMode<sup>(deprecated)</sup> 78 79isSecureMode(callback: AsyncCallback<boolean>): void 80 81判断当前设备的屏幕锁定是否安全(安全屏幕锁定意味着解锁屏幕需要密码、图案或其他用户身份识别)。使用callback异步回调。 82 83> **说明:** 84> 85> 从API version 7开始支持,从API version 9开始废弃。 86 87**系统能力:** SystemCapability.MiscServices.ScreenLock 88 89**参数:** 90 91| 参数名 | 类型 | 必填 | 说明 | 92| -------- | --------------------- | ---- | ------------------------ | 93| callback | AsyncCallback<boolean> | 是 | 回调函数。返回true表示当前设备的屏幕锁定安全;返回false表示当前设备的屏幕锁定不安全。 | 94 95**示例:** 96 97 ```ts 98 import { BusinessError } from '@ohos.base'; 99 100 screenLock.isSecureMode((err: BusinessError, data: Boolean)=>{ 101 if (err) { 102 console.error(`Failed to obtain whether the device is in secure mode, Code: ${err.code}, message: ${err.message}`); 103 return; 104 } 105 console.info(`Succeeded in Obtaining whether the device is in secure mode. result: ${data}`); 106 }); 107 ``` 108 109## screenLock.isSecureMode<sup>(deprecated)</sup> 110 111isSecureMode(): Promise<boolean> 112 113判断当前设备的屏幕锁定是否安全(安全屏幕锁定意味着解锁屏幕需要密码、图案或其他用户身份识别)。使用Promise异步回调。 114 115> **说明:** 116> 117> 从API version 7开始支持,从API version 9开始废弃。 118 119**系统能力:** SystemCapability.MiscServices.ScreenLock 120 121**返回值:** 122 123| 类型 | 说明 | 124| ---------------------- | ------------------------------------------------------------ | 125| Promise<boolean> | Promise对象。返回true表示当前设备的屏幕锁定安全;返回false表示当前设备的屏幕锁定不安全。 | 126 127**示例:** 128 129 ```ts 130 import { BusinessError } from '@ohos.base'; 131 132 screenLock.isSecureMode().then((data: Boolean) => { 133 console.info(`Succeeded in Obtaining whether the device is in secure mode. result: ${data}`); 134 }).catch((err: BusinessError) => { 135 console.error(`Failed to obtain whether the device is in secure mode, Code: ${err.code}, message: ${err.message}`); 136 }); 137 ``` 138 139## screenLock.unlockScreen<sup>(deprecated)</sup> 140 141unlockScreen(callback: AsyncCallback<void>): void 142 143解锁屏幕。使用callback异步回调。 144 145> **说明:** 146> 147> 从API version 7开始支持,从API version 9开始废弃。 148 149**系统能力:** SystemCapability.MiscServices.ScreenLock 150 151**参数:** 152 153| 参数名 | 类型 | 必填 | 说明 | 154| -------- | ------------- | ---- | --------------- | 155| callback | AsyncCallback<void> | 是 | 回调函数。解锁屏幕成功,err为undefined,否则为错误对象。 | 156 157**示例:** 158 159 ```ts 160 import { BusinessError } from '@ohos.base'; 161 162 screenLock.unlockScreen((err: BusinessError) => { 163 if (err) { 164 console.error(`Failed to unlock the screen, Code: ${err.code}, message: ${err.message}`); 165 return; 166 } 167 console.info(`Succeeded unlocking the screen.`); 168 }); 169 ``` 170 171## screenLock.unlockScreen<sup>(deprecated)</sup> 172 173unlockScreen(): Promise<void> 174 175解锁屏幕。使用Promise异步回调。 176 177> **说明:** 178> 179> 从API version 7开始支持,从API version 9开始废弃。 180 181**系统能力:** SystemCapability.MiscServices.ScreenLock 182 183**返回值:** 184 185| 类型 | 说明 | 186| ------------------- | ------------------------- | 187| Promise<void> | Promise对象。无返回结果的Promise对象。 | 188 189**示例:** 190 191 ```ts 192 import { BusinessError } from '@ohos.base'; 193 194 screenLock.unlockScreen().then(() => { 195 console.info('Succeeded unlocking the screen.'); 196 }).catch((err: BusinessError) => { 197 console.error(`Failed to unlock the screen, Code: ${err.code}, message: ${err.message}`); 198 }); 199 ``` 200