未验证 提交 96468484 编写于 作者: O openharmony_ci 提交者: Gitee

!13050 翻译完成 12901+12493+12268+12222

Merge pull request !13050 from ester.zhou/TR-12901
# Screen Lock Management
# @ohos.screenLock
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.
......@@ -12,445 +12,498 @@ The **screenlock** module is a system module in OpenHarmony. It provides APIs fo
import screenlock from '@ohos.screenLock';
```
## screenlock.isScreenLocked
isScreenLocked(callback: AsyncCallback<boolean>): void
Checks whether the screen is locked. This API uses an asynchronous callback to return the result.
## EventType
> **NOTE**
>
>This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.isLocked<sup>9+</sup>](#screenlockislocked9) instead.
Defines the system event type.
**System capability**: SystemCapability.MiscServices.ScreenLock
**Parameters**
| 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. |
| 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.|
## SystemEvent
**Example**
Defines the structure of the system event callback.
```js
screenlock.isScreenLocked((err, data)=>{
if (err) {
console.error('isScreenLocked callback error -> ${JSON.stringify(err)}');
return;
}
console.info('isScreenLocked callback success data -> ${JSON.stringify(data)}');
});
```
**System capability**: SystemCapability.MiscServices.ScreenLock
## screenlock.isScreenLocked
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ------------- |
| eventType | [EventType](#eventtype) | Yes | System event type.|
| params | string | Yes | System event parameters.|
isScreenLocked(): Promise&lt;boolean&gt;
## screenlock.isLocked<sup>9+</sup>
Checks whether the screen is locked. This API uses a promise to return the result.
isLocked(): boolean
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.isLocked<sup>9+</sup>](#screenlockislocked9) instead.
Checks whether the screen is locked.
**System capability**: SystemCapability.MiscServices.ScreenLock
**Return value**
| 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.|
| Type | Description |
| ------- | ------------------------------------------------- |
| boolean | Returns **true** if the screen is locked; returns **false** otherwise.|
**Example**
```js
screenlock.isScreenLocked().then((data) => {
console.log('isScreenLocked success: data -> ${JSON.stringify(data)}');
}).catch((err) => {
console.error('isScreenLocked fail, promise: err -> ${JSON.stringify(err)}');
});
let isLocked = screenlock.isLocked();
```
## screenlock.isLocked<sup>9+</sup>
## screenlock.isSecure<sup>9+</sup>
isLocked(): boolean
isSecure(): boolean
Checks whether the screen is locked. This API returns the result synchronously.
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.
**System capability**: SystemCapability.MiscServices.ScreenLock
**Return value**
| Type | Description |
| ------- | ------------------------------------------------- |
| boolean | Returns **true** if the screen is locked; returns **false** otherwise.|
| Type | Description |
| ------- | ------------------------------------------------------------ |
| boolean | Returns **true** if the device is in secure mode; returns **false** otherwise.|
**Example**
```js
let isLocked = screenlock.isLocked();
let isSecure = screenlock.isSecure();
```
## screenlock.isSecureMode
isSecureMode(callback: AsyncCallback&lt;boolean&gt;): void
## screenlock.unlock<sup>9+</sup>
Checks whether the device is in secure mode. This API uses an asynchronous callback to return the result.
unlock(callback: AsyncCallback&lt;boolean&gt;): void
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.isSecure<sup>9+</sup>](#screenlockissecure9) instead.
Unlocks the screen. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.ScreenLock
**Parameters**
| 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.|
| 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. |
**Example**
```js
screenlock.isSecureMode((err, data)=>{
screenlock.unlock((err, data) => {
if (err) {
console.error('isSecureMode callback error -> ${JSON.stringify(err)}');
console.error(`Failed to unlock the screen, because: ${err.message}`);
return;
}
console.info('isSecureMode callback success data -> ${JSON.stringify(err)}');
console.info(`unlock the screen successfully. result: ${data}`);
});
```
## screenlock.isSecureMode
isSecureMode(): Promise&lt;boolean&gt;
## screenlock.unlock<sup>9+</sup>
Checks whether the device is in secure mode. This API uses a promise to return the result.
unlock(): Promise&lt;boolean&gt;
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.isSecure<sup>9+</sup>](#screenlockissecure9) instead.
Unlocks the screen. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.ScreenLock
**Return value**
| 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.|
| 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. |
**Example**
```js
screenlock.isSecureMode().then((data) => {
console.log('isSecureMode success: data->${JSON.stringify(data)}');
screenlock.unlock().then((data) => {
console.info(`unlock the screen successfully. result: ${data}`);
}).catch((err) => {
console.error('isSecureMode fail, promise: err->${JSON.stringify(err)}');
console.error(`Failed to unlock the screen, because: ${err.message}`);
});
```
## screenlock.isSecure<sup>9+</sup>
## screenlock.lock<sup>9+</sup>
isSecure(): boolean
lock(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether the device is in secure mode.
Locks the screen. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.ScreenLock
**Return value**
**System API**: This is a system API.
| Type | Description |
| ------- | ------------------------------------------------------------ |
| boolean | The value **true** means that the device is in secure mode, and **false** means the opposite.|
**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. |
**Example**
```js
let isSecure = screenlock.isSecure();
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}`);
});
```
## screenlock.unlockScreen
unlockScreen(callback: AsyncCallback&lt;void&gt;): void
## screenlock.lock<sup>9+</sup>
Unlocks the screen. This API uses an asynchronous callback to return the result.
lock(): Promise&lt;boolean&gt;
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.unlock<sup>9+</sup>](#screenlockunlock9) instead.
Locks the screen. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.ScreenLock
**Parameters**
**System API**: This is a system API.
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | --------------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation fails, an error message is returned.|
**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. |
**Example**
```js
screenlock.unlockScreen((err) => {
if (err) {
console.error('unlockScreen callback error -> ${JSON.stringify(err)}');
return;
}
console.info('unlockScreen callback success');
screenlock.lock().then((data) => {
console.info(`lock the screen successfully. result: ${data}`);
}).catch((err) => {
console.error(`Failed to lock the screen, because: ${err.message}`);
});
```
## screenlock.unlockScreen
unlockScreen(): Promise&lt;void&gt;
## screenlock.onSystemEvent<sup>9+</sup>
Unlocks the screen. This API uses a promise to return the result.
onSystemEvent(callback: Callback&lt;SystemEvent&gt;): boolean
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.unlock<sup>9+</sup>](#screenlockunlock9) instead.
Registers a callback for system events related to screen locking.
**System capability**: SystemCapability.MiscServices.ScreenLock
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------- |
| callback | Callback\<[SystemEvent](#systemevent)> | Yes | Callback for system events related to screen locking.|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| 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. |
**Example**
```js
screenlock.unlockScreen().then(() => {
console.log('unlockScreen success');
}).catch((err) => {
console.error('unlockScreen fail, promise: err->${JSON.stringify(err)}');
});
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}`)
}
```
## screenlock.unlock<sup>9+</sup>
## screenlock.sendScreenLockEvent<sup>9+</sup>
unlock(callback: AsyncCallback&lt;boolean&gt;): void
sendScreenLockEvent(event: string, parameter: number, callback: AsyncCallback&lt;boolean&gt;): void
Unlocks the screen. This API uses an asynchronous callback to return the result.
Sends an event to the screen lock service. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.ScreenLock
**System API**: This is a system API.
**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 unlocked successfully, and **false** means the opposite.|
| Name | Type | Mandatory| Description |
| --------- | ------------------------ | ---- | -------------------- |
| event | string | Yes | Event type.<br>- **"unlockScreenResult"**: Screen unlock result.<br>- **"lockScreenResult"**: Screen lock result.<br>- **"screenDrawDone"**: Screen drawing is complete.|
| 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. |
**Example**
```js
screenlock.unlock((err,data) => {
screenlock.sendScreenLockEvent('unlockScreenResult', 0, (err, result) => {
if (err) {
console.error('unlock error -> ${JSON.stringify(err)}');
return;
console.error(`Failed to send screenlock event, because: ${err.message}`);
return;
}
console.info('unlock success data -> ${JSON.stringify(data)}');
console.info(`Send screenlock event successfully. result: ${result}`);
});
```
## screenlock.unlock<sup>9+</sup>
## screenlock.sendScreenLockEvent<sup>9+</sup>
unlock(): Promise&lt;boolean&gt;
sendScreenLockEvent(event: string, parameter: number): Promise&lt;boolean&gt;
Unlocks the screen. This API uses a promise to return the result.
Sends an event to the screen lock service. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.ScreenLock
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | --------------------------------------- |
| event | string | Yes | Event type.<br>- **"unlockScreenResult"**: Screen unlock result.<br>- **"lockScreenResult"**: Screen lock result.<br>- **"screenDrawDone"**: Screen drawing is complete.|
| 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.|
**Return value**
| 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.|
| 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.|
**Example**
```js
screenlock.unlock().then((data) => {
console.log('unlock success');
screenlock.sendScreenLockEvent('unlockScreenResult', 0).then((result) => {
console.info(`Send screenlock event successfully. result: ${result}`);
}).catch((err) => {
console.error('unlock fail, : err->${JSON.stringify(err)}');
console.error(`Failed to send screenlock event, because: ${err.message}`);
});
```
## screenlock.lock<sup>9+</sup>
## screenlock.isScreenLocked<sup>(deprecated)</sup>
lock(callback: AsyncCallback&lt;boolean&gt;): void
isScreenLocked(callback: AsyncCallback&lt;boolean&gt;): void
Locks the screen. This API uses an asynchronous callback to return the result.
Checks whether the screen is locked. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.ScreenLock
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.isLocked<sup>9+</sup>](#screenlockislocked9) instead.
**System API**: This is a system API.
**System capability**: SystemCapability.MiscServices.ScreenLock
**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.|
| 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.|
**Example**
```js
screenlock.lock((err,data) => {
screenlock.isScreenLocked((err, data)=>{
if (err) {
console.error('lock callback error -> ${JSON.stringify(err)}');
console.error(`Failed to obtain whether the screen is locked, because: ${err.message}`);
return;
}
console.info('lock callback success');
console.info(`Obtain whether the screen is locked successfully. result: ${data}`);
});
```
## screenlock.lock<sup>9+</sup>
## screenlock.isScreenLocked<sup>(deprecated)</sup>
lock(): Promise&lt;boolean&gt;
isScreenLocked(): Promise&lt;boolean&gt;
Locks the screen. This API uses a promise to return the result.
Checks whether the screen is locked. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.ScreenLock
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.isLocked<sup>9+</sup>](#screenlockislocked9) instead.
**System API**: This is a system API.
**System capability**: SystemCapability.MiscServices.ScreenLock
**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.|
| 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.|
**Example**
```js
screenlock.lock().then((data) => {
console.log('lock success');
screenlock.isScreenLocked().then((data) => {
console.info(`Obtain whether the screen is locked successfully. result: ${data}`);
}).catch((err) => {
console.error('lock fail, promise: err->${JSON.stringify(err)}');
console.error(`Failed to obtain whether the screen is locked, because: ${err.message}`);
});
```
## EventType
Defines the system event type.
**System capability**: SystemCapability.MiscServices.ScreenLock
| Event Type | Description |
| ------------------ | ------------------------ |
| beginWakeUp | Wakeup starts when the event starts.|
| endWakeUp | Wakeup ends when the event ends.|
| beginScreenOn | Screen turn-on starts when the event starts.|
| endScreenOn | Screen turn-on ends when the event ends.|
| beginScreenOff | Screen turn-off starts when the event starts.|
| endScreenOff | Screen turn-off ends when the event ends.|
| unlockScreen | The screen is unlocked. |
| lockScreen | The screen is locked. |
| beginExitAnimation | Animation starts to exit. |
| beginSleep | The screen enters sleep mode. |
| endSleep | The screen exits sleep mode. |
| changeUser | The user is switched. |
| screenlockEnabled | Screen lock is enabled. |
| serviceRestart | The screen lock service is restarted. |
## screenlock.isSecureMode<sup>(deprecated)</sup>
isSecureMode(callback: AsyncCallback&lt;boolean&gt;): void
## SystemEvent
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.
Defines the structure of the system event callback.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.isSecure<sup>9+</sup>](#screenlockissecure9) instead.
**System capability**: SystemCapability.MiscServices.ScreenLock
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ------------- |
| eventType | [EventType](#eventtype) | Yes | System event type.|
| params | string | Yes | System event parameters.|
**Parameters**
## screenlock.onSystemEvent<sup>9+</sup>
| 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.|
onSystemEvent(callback: Callback\<SystemEvent\>): boolean
**Example**
Registers a callback for system events related to screen locking.
```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}`);
});
```
**System capability**: SystemCapability.MiscServices.ScreenLock
## screenlock.isSecureMode<sup>(deprecated)</sup>
**System API**: This is a system API.
isSecureMode(): Promise&lt;boolean&gt;
**Parameters**
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.
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------- | ---- | ---------------------------- |
| callback | Callback\<[SystemEvent](#systemevent)> | Yes | Callback for system events related to screen locking.|
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.isSecure<sup>9+</sup>](#screenlockissecure9) instead.
**System capability**: SystemCapability.MiscServices.ScreenLock
**Return value**
| Type | Description |
| ------- | ------------------------------------------------- |
| boolean | Returns **true** if the callback is registered successfully; returns **false** otherwise.|
| 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.|
**Example**
```js
let isSuccess = screenlock.onSystemEvent((event)=>{
console.log(`onSystemEvent:callback:${event.eventType}`)
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}`);
});
if (!isSuccess) {
console.log(`onSystemEvent result is false`)
}
```
## screenlock.unlockScreen<sup>(deprecated)</sup>
## screenlock.sendScreenLockEvent<sup>9+</sup>
unlockScreen(callback: AsyncCallback&lt;void&gt;): void
sendScreenLockEvent(event: String, parameter: number, callback: AsyncCallback\<boolean>): void
Unlocks the screen. This API uses an asynchronous callback to return the result.
Sends an event to the screen lock service. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.unlock<sup>9+</sup>](#screenlockunlock9) instead.
**System capability**: SystemCapability.MiscServices.ScreenLock
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------ | ---- | -------------------- |
| event | String | Yes | Event type.<br>- **"unlockScreenResult"**: Screen unlock result.<br>- **"screenDrawDone"**: Screen drawing is complete.|
| parameter | number | Yes | Screen unlock status.<br>- **0**: The unlock is successful.<br>- **1**: The unlock failed.<br>- **2**: The unlock was canceled.|
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. The value **true** means that the operation is successful, and **false** means the opposite. |
| 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.|
**Example**
```js
screenlock.sendScreenLockEvent('unlockScreenResult', 0, (err, result) => {
console.log('sending result:' + result);
screenlock.unlockScreen((err) => {
if (err) {
console.error(`Failed to unlock the screen, because: ${err.message}`);
return;
}
console.info('unlock the screen successfully.');
});
```
## screenlock.sendScreenLockEvent<sup>9+</sup>
sendScreenLockEvent(event: String, parameter: number): Promise\<boolean>
Sends an event to the screen lock service. This API uses a promise to return the result.
## screenlock.unlockScreen<sup>(deprecated)</sup>
**System capability**: SystemCapability.MiscServices.ScreenLock
unlockScreen(): Promise&lt;void&gt;
**System API**: This is a system API.
Unlocks the screen. This API uses a promise to return the result.
**Parameters**
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.unlock<sup>9+</sup>](#screenlockunlock9) instead.
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | --------------------------------------- |
| event | String | Yes | Event type.<br>- **"unlockScreenResult"**: Screen unlock result.<br>- **"screenDrawDone"**: Screen drawing is complete.|
| parameter | number | Yes | Screen unlock status.<br>- **0**: The unlock is successful.<br>- **1**: The unlock failed.<br>- **2**: The unlock was canceled.|
**System capability**: SystemCapability.MiscServices.ScreenLock
**Return value**
| Type | Description |
| ------------------ | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.|
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
screenlock.sendScreenLockEvent('unlockScreenResult', 0).then((result) => {
console.log('sending result:' + result);
screenlock.unlockScreen().then(() => {
console.info('unlock the screen successfully.');
}).catch((err) => {
console.error(`Failed to unlock the screen, because: ${err.message}`);
});
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册