js-apis-screen-lock.md 17.9 KB
Newer Older
E
ester.zhou 已提交
1
# @ohos.screenLock (Screen Lock)
G
ge-yafang 已提交
2

3 4
The **screenlock** module is a system module in OpenHarmony. It provides APIs for screen lock applications to subscribe to screen lock status changes as well as callbacks for them to receive the results. It also provides APIs for third-party applications to unlock the screen, obtain the screen locked status, and check whether a lock screen password has been set.

E
uu  
ester.zhou 已提交
5 6
> **NOTE**
>
7
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
G
ge-yafang 已提交
8 9 10

## Modules to Import

S
shawn_he 已提交
11
```js
G
ge-yafang 已提交
12 13 14
import screenlock from '@ohos.screenLock';
```

E
ester.zhou 已提交
15
## EventType<sup>9+</sup>
G
ge-yafang 已提交
16

E
esterzhou 已提交
17
Defines the system event type.
E
ester.zhou 已提交
18

G
ge-yafang 已提交
19 20
**System capability**: SystemCapability.MiscServices.ScreenLock

E
ester.zhou 已提交
21 22
**System API**: This is a system API.

E
esterzhou 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| Event Type           | Description                    |
| ------------------ | ------------------------ |
| beginWakeUp        | Wakeup starts.|
| endWakeUp          | Wakeup ends.|
| beginScreenOn      | Screen turn-on starts.|
| endScreenOn        | Screen turn-on ends.|
| beginScreenOff     | Screen turn-off starts.|
| endScreenOff       | Screen turn-off ends.|
| unlockScreen       | The screen is unlocked.      |
| lockScreen         | The screen is locked.      |
| beginExitAnimation | Exit animation starts.      |
| beginSleep         | The device enters sleep mode.          |
| endSleep           | The device exits sleep mode.          |
| changeUser         | The user is switched.          |
| screenlockEnabled  | Screen lock is enabled.      |
| serviceRestart     | The screen lock service is restarted.  |
E
ester.zhou 已提交
39

E
ester.zhou 已提交
40
## SystemEvent<sup>9+</sup>
E
uu  
ester.zhou 已提交
41

E
esterzhou 已提交
42
Defines the structure of the system event callback.
G
ge-yafang 已提交
43

E
esterzhou 已提交
44
**System capability**: SystemCapability.MiscServices.ScreenLock
G
ge-yafang 已提交
45

E
ester.zhou 已提交
46 47
**System API**: This is a system API.

E
esterzhou 已提交
48 49
| Name   | Type  | Mandatory|       Description       |
| --------- | ------ | ---- | ------------- |
E
ester.zhou 已提交
50
| eventType   | [EventType](#eventtype9) | Yes  | System event type.|
E
esterzhou 已提交
51
| params | string | Yes  | System event parameters.|
G
ge-yafang 已提交
52

E
esterzhou 已提交
53
## screenlock.isLocked<sup>9+</sup>
G
ge-yafang 已提交
54

E
esterzhou 已提交
55
isLocked(): boolean
G
ge-yafang 已提交
56

E
esterzhou 已提交
57
Checks whether the screen is locked.
E
ester.zhou 已提交
58

G
ge-yafang 已提交
59 60
**System capability**: SystemCapability.MiscServices.ScreenLock

E
ester.zhou 已提交
61 62
**System API**: This is a system API.

E
uu  
ester.zhou 已提交
63
**Return value**
E
ester.zhou 已提交
64

E
esterzhou 已提交
65 66 67
| Type   | Description                                             |
| ------- | ------------------------------------------------- |
| boolean | Returns **true** if the screen is locked; returns **false** otherwise.|
E
uu  
ester.zhou 已提交
68 69

**Example**
G
ge-yafang 已提交
70

E
ester.zhou 已提交
71
```js
E
esterzhou 已提交
72
let isLocked = screenlock.isLocked();
E
ester.zhou 已提交
73
```
G
ge-yafang 已提交
74

E
esterzhou 已提交
75
## screenlock.unlock<sup>9+</sup>
G
ge-yafang 已提交
76

E
esterzhou 已提交
77
unlock(callback: AsyncCallback&lt;boolean&gt;): void
G
ge-yafang 已提交
78

E
esterzhou 已提交
79
Unlocks the screen. This API uses an asynchronous callback to return the result.
G
ge-yafang 已提交
80 81 82

**System capability**: SystemCapability.MiscServices.ScreenLock

E
ester.zhou 已提交
83 84
**System API**: This is a system API.

E
uu  
ester.zhou 已提交
85
**Parameters**
E
ester.zhou 已提交
86

E
esterzhou 已提交
87 88 89 90 91 92 93 94 95 96 97
| Name  | Type         | Mandatory| Description                                |
| -------- | --------------------- | ---- | ------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. The value **true** means that the screen is unlocked successfully, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 13200002  | The screenlock management service is abnormal.         |
G
ge-yafang 已提交
98

E
uu  
ester.zhou 已提交
99
**Example**
G
ge-yafang 已提交
100

E
ester.zhou 已提交
101
```js
E
esterzhou 已提交
102
screenlock.unlock((err, data) => {      
E
ester.zhou 已提交
103
    if (err) {
E
esterzhou 已提交
104
        console.error(`Failed to unlock the screen, because: ${err.message}`);
E
ester.zhou 已提交
105 106
        return;    
    }
E
esterzhou 已提交
107
    console.info(`unlock the screen successfully. result: ${data}`);
E
ester.zhou 已提交
108 109
});
```
G
ge-yafang 已提交
110

E
esterzhou 已提交
111
## screenlock.unlock<sup>9+</sup>
G
ge-yafang 已提交
112

E
esterzhou 已提交
113
unlock(): Promise&lt;boolean&gt;
E
ester.zhou 已提交
114

E
esterzhou 已提交
115
Unlocks the screen. This API uses a promise to return the result.
G
ge-yafang 已提交
116 117 118

**System capability**: SystemCapability.MiscServices.ScreenLock

E
ester.zhou 已提交
119 120
**System API**: This is a system API.

E
uu  
ester.zhou 已提交
121
**Return value**
E
ester.zhou 已提交
122

E
esterzhou 已提交
123 124 125 126 127 128 129 130 131 132 133
| Type               | Description                                                        |
| ------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the screen is unlocked successfully, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 13200002  | The screenlock management service is abnormal.         |
E
uu  
ester.zhou 已提交
134 135

**Example**
G
ge-yafang 已提交
136

E
ester.zhou 已提交
137
```js
E
esterzhou 已提交
138 139
screenlock.unlock().then((data) => {
    console.info(`unlock the screen successfully. result: ${data}`);
E
ester.zhou 已提交
140
}).catch((err) => {
E
esterzhou 已提交
141
    console.error(`Failed to unlock the screen, because: ${err.message}`);
E
ester.zhou 已提交
142 143 144
});
```

E
esterzhou 已提交
145
## screenlock.lock<sup>9+</sup>
E
ester.zhou 已提交
146

E
esterzhou 已提交
147
lock(callback: AsyncCallback&lt;boolean&gt;): void
G
ge-yafang 已提交
148

E
esterzhou 已提交
149
Locks the screen. This API uses an asynchronous callback to return the result.
E
ester.zhou 已提交
150 151 152

**System capability**: SystemCapability.MiscServices.ScreenLock

E
ester.zhou 已提交
153 154
**Required permissions**: ohos.permission.ACCESS_SCREEN_LOCK_INNER

E
esterzhou 已提交
155
**System API**: This is a system API.
E
ester.zhou 已提交
156

E
esterzhou 已提交
157 158 159 160 161 162 163 164 165 166 167 168 169
**Parameters**

| Name  | Type         | Mandatory| Description                     |
| -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. The value **true** means that the screen is locked successfully, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 13200002  | The screenlock management service is abnormal.         |
E
ester.zhou 已提交
170 171 172 173

**Example**

```js
E
esterzhou 已提交
174 175 176 177 178 179 180
screenlock.lock((err, data) => {      
    if (err) {
        console.error(`Failed to lock the screen, because: ${err.message}`);
        return;    
    }
    console.info(`lock the screen successfully. result: ${data}`);
});
E
ester.zhou 已提交
181
```
G
ge-yafang 已提交
182

E
esterzhou 已提交
183
## screenlock.lock<sup>9+</sup>
G
ge-yafang 已提交
184

E
esterzhou 已提交
185
lock(): Promise&lt;boolean&gt;
G
ge-yafang 已提交
186

E
esterzhou 已提交
187
Locks the screen. This API uses a promise to return the result.
G
ge-yafang 已提交
188 189 190

**System capability**: SystemCapability.MiscServices.ScreenLock

E
ester.zhou 已提交
191 192
**Required permissions**: ohos.permission.ACCESS_SCREEN_LOCK_INNER

E
esterzhou 已提交
193
**System API**: This is a system API.
E
ester.zhou 已提交
194

E
esterzhou 已提交
195 196 197 198 199 200 201 202 203 204 205 206 207
**Return value**

| Type                  | Description                                                        |
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the screen is locked successfully, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 13200002  | The screenlock management service is abnormal.         |
G
ge-yafang 已提交
208

E
uu  
ester.zhou 已提交
209
**Example**
G
ge-yafang 已提交
210

E
ester.zhou 已提交
211
```js
E
esterzhou 已提交
212 213 214 215
screenlock.lock().then((data) => {
    console.info(`lock the screen successfully. result: ${data}`);
}).catch((err) => {
    console.error(`Failed to lock the screen, because: ${err.message}`);
E
ester.zhou 已提交
216 217
});
```
G
ge-yafang 已提交
218

E
esterzhou 已提交
219
## screenlock.onSystemEvent<sup>9+</sup>
G
ge-yafang 已提交
220

E
esterzhou 已提交
221
onSystemEvent(callback: Callback&lt;SystemEvent&gt;): boolean
G
ge-yafang 已提交
222

E
ester.zhou 已提交
223
Registers a callback for system events related to screen locking. This API can be called only by system screen lock applications.
E
ester.zhou 已提交
224

G
ge-yafang 已提交
225 226
**System capability**: SystemCapability.MiscServices.ScreenLock

E
ester.zhou 已提交
227 228
**Required permissions**: ohos.permission.ACCESS_SCREEN_LOCK_INNER

E
esterzhou 已提交
229 230 231 232 233 234
**System API**: This is a system API.

**Parameters**

| Name  | Type                       | Mandatory| Description              |
| -------- | ------------------------- | ---- | ----------------- |
E
ester.zhou 已提交
235
| callback | Callback\<[SystemEvent](#systemevent9)> | Yes  | Callback for system events related to screen locking.|
E
esterzhou 已提交
236

E
uu  
ester.zhou 已提交
237
**Return value**
E
ester.zhou 已提交
238

E
esterzhou 已提交
239 240 241 242 243 244 245 246 247 248 249
| Type   | Description                                             |
| ------- | ------------------------------------------------- |
| boolean | Returns **true** if the callback is registered successfully; returns **false** otherwise.|

**Error codes**

For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 13200002  | The screenlock management service is abnormal.         |
E
uu  
ester.zhou 已提交
250 251

**Example**
G
ge-yafang 已提交
252

E
ester.zhou 已提交
253
```js
E
esterzhou 已提交
254 255 256 257 258 259 260
try {
    let isSuccess = screenlock.onSystemEvent((event) => {
        console.log(`Register the system event which related to screenlock successfully. eventType: ${event.eventType}`)
    });
} catch (err) {
    console.error(`Failed to register the system event which related to screenlock, because: ${err.message}`)
}
E
ester.zhou 已提交
261
```
E
uu  
ester.zhou 已提交
262

E
esterzhou 已提交
263
## screenlock.sendScreenLockEvent<sup>9+</sup>
264

E
ester.zhou 已提交
265
sendScreenLockEvent(event: String, parameter: number, callback: AsyncCallback&lt;boolean&gt;): void
266

E
esterzhou 已提交
267
Sends an event to the screen lock service. This API uses an asynchronous callback to return the result.
268

E
ester.zhou 已提交
269
**System capability**: SystemCapability.MiscServices.ScreenLock
270

E
ester.zhou 已提交
271 272
**Required permissions**: ohos.permission.ACCESS_SCREEN_LOCK_INNER

E
esterzhou 已提交
273 274
**System API**: This is a system API.

E
ester.zhou 已提交
275 276
**Parameters**

E
esterzhou 已提交
277 278
| Name   | Type           | Mandatory| Description                            |
| --------- | ------------------------ | ---- | -------------------- |
E
ester.zhou 已提交
279
| event     | String                   | Yes  | Event type.<br>- **"unlockScreenResult"**: Screen unlock result.<br>- **"lockScreenResult"**: Screen lock result.<br>- **"screenDrawDone"**: Screen drawing is complete.|
E
esterzhou 已提交
280 281 282 283 284 285 286 287 288 289
| parameter | number                   | Yes  | Result.<br>- **0**: The operation is successful. For example, the screen is locked or unlocked successfully.<br>- **1**, the operation fails. For example, screen locking or unlocking fails.<br>- **2**: The operation is canceled. For example, screen locking or unlocking is canceled.|
| callback  | AsyncCallback\<boolean> | Yes  | Callback used to return the result. The **value** true means that the event is sent successfully, and **false** means the opposite.                |

**Error codes**

For details about the error codes, see [Screen Lock Management Error Codes](../errorcodes/errorcode-screenlock.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 13200002  | The screenlock management service is abnormal.         |
E
ester.zhou 已提交
290 291 292 293

**Example**

```js
E
esterzhou 已提交
294
screenlock.sendScreenLockEvent('unlockScreenResult', 0, (err, result) => {
E
ester.zhou 已提交
295
    if (err) {
E
esterzhou 已提交
296 297
        console.error(`Failed to send screenlock event, because: ${err.message}`);
        return;
E
ester.zhou 已提交
298
    }
E
esterzhou 已提交
299
    console.info(`Send screenlock event successfully. result: ${result}`);
E
ester.zhou 已提交
300 301 302
});
```

E
esterzhou 已提交
303
## screenlock.sendScreenLockEvent<sup>9+</sup>
E
ester.zhou 已提交
304

E
ester.zhou 已提交
305
sendScreenLockEvent(event: String, parameter: number): Promise&lt;boolean&gt;
E
ester.zhou 已提交
306

E
esterzhou 已提交
307
Sends an event to the screen lock service. This API uses a promise to return the result.
E
ester.zhou 已提交
308 309 310

**System capability**: SystemCapability.MiscServices.ScreenLock

E
ester.zhou 已提交
311 312
**Required permissions**: ohos.permission.ACCESS_SCREEN_LOCK_INNER

E
esterzhou 已提交
313 314 315 316 317 318
**System API**: This is a system API.

**Parameters**

| Name   | Type  | Mandatory| Description                                      |
| --------- | ------ | ---- | --------------------------------------- |
E
ester.zhou 已提交
319
| event     | String | Yes  | Event type.<br>- **"unlockScreenResult"**: Screen unlock result.<br>- **"lockScreenResult"**: Screen lock result.<br>- **"screenDrawDone"**: Screen drawing is complete.|
E
esterzhou 已提交
320 321
| parameter | number | Yes  | Result.<br>- **0**: The operation is successful. For example, the screen is locked or unlocked successfully.<br>- **1**, the operation fails. For example, screen locking or unlocking fails.<br>- **2**: The operation is canceled. For example, screen locking or unlocking is canceled.|

E
ester.zhou 已提交
322
**Return value**
323

E
esterzhou 已提交
324 325 326
| Type              | Description                                          |
| ----------------- | ---------------------------------------------- |
| Promise\<boolean> | Promise used to return the result. The **value** true means that the event is sent successfully, and **false** means the opposite.|
E
ester.zhou 已提交
327 328 329 330

**Example**

```js
E
esterzhou 已提交
331 332
screenlock.sendScreenLockEvent('unlockScreenResult', 0).then((result) => {
    console.info(`Send screenlock event successfully. result: ${result}`);
E
ester.zhou 已提交
333
}).catch((err) => {
E
esterzhou 已提交
334
    console.error(`Failed to send screenlock event, because: ${err.message}`);
E
ester.zhou 已提交
335 336 337
});
```

E
esterzhou 已提交
338
## screenlock.isScreenLocked<sup>(deprecated)</sup>
E
ester.zhou 已提交
339

E
esterzhou 已提交
340
isScreenLocked(callback: AsyncCallback&lt;boolean&gt;): void
E
ester.zhou 已提交
341

E
esterzhou 已提交
342
Checks whether the screen is locked. This API uses an asynchronous callback to return the result.
343

E
esterzhou 已提交
344 345
> **NOTE**
> 
E
ester.zhou 已提交
346
> This API is supported since API version 7 and deprecated since API version 9.
347

E
esterzhou 已提交
348
**System capability**: SystemCapability.MiscServices.ScreenLock
349 350

**Parameters**
E
ester.zhou 已提交
351

E
esterzhou 已提交
352 353 354
| Name  | Type                        | Mandatory| Description                                                       |
| -------- | ---------------------------- | ---- | ----------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. The value **true** means that the screen is locked, and **false** means the opposite.|
355 356 357

**Example**

E
ester.zhou 已提交
358
```js
E
esterzhou 已提交
359
screenlock.isScreenLocked((err, data)=>{      
E
ester.zhou 已提交
360
    if (err) {
E
esterzhou 已提交
361
        console.error(`Failed to obtain whether the screen is locked, because: ${err.message}`);
E
ester.zhou 已提交
362 363
        return;    
    }
E
esterzhou 已提交
364
    console.info(`Obtain whether the screen is locked successfully. result: ${data}`);
E
ester.zhou 已提交
365 366
});
```
367

E
esterzhou 已提交
368
## screenlock.isScreenLocked<sup>(deprecated)</sup>
369

E
esterzhou 已提交
370
isScreenLocked(): Promise&lt;boolean&gt;
371

E
esterzhou 已提交
372
Checks whether the screen is locked. This API uses a promise to return the result.
373

E
esterzhou 已提交
374 375
> **NOTE**
> 
E
ester.zhou 已提交
376
> This API is supported since API version 7 and deprecated since API version 9.
377

E
esterzhou 已提交
378
**System capability**: SystemCapability.MiscServices.ScreenLock
379 380 381

**Return value**

E
esterzhou 已提交
382 383 384
| Type                  | Description                                        |
| ---------------------- | ------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the screen is locked, and **false** means the opposite.|
385 386 387

**Example**

E
ester.zhou 已提交
388
```js
E
esterzhou 已提交
389 390
screenlock.isScreenLocked().then((data) => {
    console.info(`Obtain whether the screen is locked successfully. result: ${data}`);
E
ester.zhou 已提交
391
}).catch((err) => {
E
esterzhou 已提交
392
    console.error(`Failed to obtain whether the screen is locked, because: ${err.message}`);
E
ester.zhou 已提交
393 394
});
```
395

E
esterzhou 已提交
396
## screenlock.isSecureMode<sup>(deprecated)</sup>
E
ester.zhou 已提交
397

E
esterzhou 已提交
398
isSecureMode(callback: AsyncCallback&lt;boolean&gt;): void
E
ester.zhou 已提交
399

E
esterzhou 已提交
400
Checks whether the device is in secure mode. When the device is in secure mode, its screen requires a password, unlock pattern, or other user credentials to unlock. This API uses an asynchronous callback to return the result.
E
ester.zhou 已提交
401

E
esterzhou 已提交
402 403
> **NOTE**
> 
E
ester.zhou 已提交
404
> This API is supported since API version 7 and deprecated since API version 9.
E
uu  
ester.zhou 已提交
405 406 407

**System capability**: SystemCapability.MiscServices.ScreenLock

E
esterzhou 已提交
408
**Parameters**
E
uu  
ester.zhou 已提交
409

E
esterzhou 已提交
410 411 412
| Name  | Type           | Mandatory| Description                             |
| -------- | --------------------- | ---- | ------------------------ |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. The value **true** means that the device is in secure mode, and **false** means the opposite.|
E
uu  
ester.zhou 已提交
413

E
esterzhou 已提交
414
**Example**
E
uu  
ester.zhou 已提交
415

E
esterzhou 已提交
416 417 418 419 420 421 422 423 424
```js
screenlock.isSecureMode((err, data)=>{
    if (err) {
        console.error(`Failed to obtain whether the device is in secure mode, because: ${err.message}`);
        return;
    }
    console.info(`Obtain whether the device is in secure mode successfully. result: ${data}`);
});
```
E
uu  
ester.zhou 已提交
425

E
esterzhou 已提交
426
## screenlock.isSecureMode<sup>(deprecated)</sup>
E
uu  
ester.zhou 已提交
427

E
esterzhou 已提交
428
isSecureMode(): Promise&lt;boolean&gt;
429

E
esterzhou 已提交
430
Checks whether the device is in secure mode. When the device is in secure mode, its screen requires a password, unlock pattern, or other user credentials to unlock. This API uses a promise to return the result.
E
ester.zhou 已提交
431

E
esterzhou 已提交
432 433
> **NOTE**
> 
E
ester.zhou 已提交
434
> This API is supported since API version 7 and deprecated since API version 9.
E
esterzhou 已提交
435 436

**System capability**: SystemCapability.MiscServices.ScreenLock
E
uu  
ester.zhou 已提交
437

E
ester.zhou 已提交
438
**Return value**
E
ester.zhou 已提交
439

E
esterzhou 已提交
440 441 442
| Type                  | Description                                                        |
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the device is in secure mode, and **false** means the opposite.|
E
uu  
ester.zhou 已提交
443 444 445

**Example**

E
ester.zhou 已提交
446
```js
E
esterzhou 已提交
447 448 449 450
screenlock.isSecureMode().then((data) => {
    console.info(`Obtain whether the device is in secure mode successfully. result: ${data}`);
}).catch((err) => {
    console.error(`Failed to obtain whether the device is in secure mode, because: ${err.message}`);
E
ester.zhou 已提交
451 452
});
```
E
esterzhou 已提交
453
## screenlock.unlockScreen<sup>(deprecated)</sup>
E
uu  
ester.zhou 已提交
454

E
esterzhou 已提交
455
unlockScreen(callback: AsyncCallback&lt;void&gt;): void
E
uu  
ester.zhou 已提交
456

E
esterzhou 已提交
457
Unlocks the screen. This API uses an asynchronous callback to return the result.
E
uu  
ester.zhou 已提交
458

E
esterzhou 已提交
459 460
> **NOTE**
> 
E
ester.zhou 已提交
461
> This API is supported since API version 7 and deprecated since API version 9.
E
uu  
ester.zhou 已提交
462 463 464 465

**System capability**: SystemCapability.MiscServices.ScreenLock

**Parameters**
E
ester.zhou 已提交
466

E
esterzhou 已提交
467 468 469
| Name  | Type             | Mandatory| Description            |
| -------- | ------------- | ---- | --------------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the screen is unlocked successfully, **err** is **undefined**; otherwise, **err** is an error object.|
E
uu  
ester.zhou 已提交
470 471 472

**Example**

E
ester.zhou 已提交
473
```js
E
esterzhou 已提交
474 475 476 477 478 479
screenlock.unlockScreen((err) => {      
    if (err) {
        console.error(`Failed to unlock the screen, because: ${err.message}`);
        return;    
    }
    console.info('unlock the screen successfully.');
E
ester.zhou 已提交
480 481
});
```
E
uu  
ester.zhou 已提交
482

E
esterzhou 已提交
483
## screenlock.unlockScreen<sup>(deprecated)</sup>
E
uu  
ester.zhou 已提交
484

E
esterzhou 已提交
485
unlockScreen(): Promise&lt;void&gt;
E
uu  
ester.zhou 已提交
486

E
esterzhou 已提交
487
Unlocks the screen. This API uses a promise to return the result.
E
uu  
ester.zhou 已提交
488

E
esterzhou 已提交
489 490
> **NOTE**
> 
E
ester.zhou 已提交
491
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
492

E
esterzhou 已提交
493
**System capability**: SystemCapability.MiscServices.ScreenLock
E
uu  
ester.zhou 已提交
494 495

**Return value**
E
ester.zhou 已提交
496

E
esterzhou 已提交
497 498 499
| Type               | Description                     |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
E
uu  
ester.zhou 已提交
500 501 502

**Example**

E
ester.zhou 已提交
503
```js
E
esterzhou 已提交
504 505 506 507
screenlock.unlockScreen().then(() => {
    console.info('unlock the screen successfully.');
}).catch((err) => {
    console.error(`Failed to unlock the screen, because: ${err.message}`);
E
ester.zhou 已提交
508 509
});
```