鎖屏管理

2024-01-23 17:26 更新

鎖屏管理服務(wù)是HarmonyOS中的系統(tǒng)服務(wù),為鎖屏應(yīng)用提供注冊亮屏、滅屏、開啟屏幕、結(jié)束休眠、退出動畫、請求解鎖結(jié)果監(jiān)聽,并提供回調(diào)結(jié)果給鎖屏應(yīng)用。鎖屏管理服務(wù)向三方應(yīng)用提供請求解鎖、查詢鎖屏狀態(tài)、查詢是否設(shè)置鎖屏密碼的能力。

說明

本模塊首批接口從API version 7開始支持。后續(xù)版本的新增接口,采用上角標單獨標記接口的起始版本。

導(dǎo)入模塊

  1. import screenLock from '@ohos.screenLock';

screenLock.isScreenLocked(deprecated)

isScreenLocked(callback: AsyncCallback<boolean>): void

判斷屏幕是否鎖屏。使用callback異步回調(diào)。

說明

從API version 7開始支持,從API version 9開始廢棄。

系統(tǒng)能力: SystemCapability.MiscServices.ScreenLock

參數(shù):

參數(shù)名

類型

必填

說明

callback

AsyncCallback<boolean>

回調(diào)函數(shù)。返回true表示屏幕已鎖屏;返回false表示屏幕未鎖屏。

示例:

  1. screenLock.isScreenLocked((err, data)=>{
  2. if (err) {
  3. console.error(`Failed to obtain whether the screen is locked, because: ${err.message}`);
  4. return;
  5. }
  6. console.info(`Obtain whether the screen is locked successfully. result: ${data}`);
  7. });

screenLock.isScreenLocked(deprecated)

isScreenLocked(): Promise<boolean>

判斷屏幕是否鎖屏。使用Promise異步回調(diào)。

說明

從API version 7開始支持,從API version 9開始廢棄。

系統(tǒng)能力: SystemCapability.MiscServices.ScreenLock

返回值:

類型

說明

Promise<boolean>

Promise對象。返回true表示屏幕已鎖屏;返回false表示屏幕未鎖屏。

示例:

  1. screenLock.isScreenLocked().then((data) => {
  2. console.info(`Obtain whether the screen is locked successfully. result: ${data}`);
  3. }).catch((err) => {
  4. console.error(`Failed to obtain whether the screen is locked, because: ${err.message}`);
  5. });

screenLock.isSecureMode(deprecated)

isSecureMode(callback: AsyncCallback<boolean>): void

判斷當前設(shè)備的屏幕鎖定是否安全(安全屏幕鎖定意味著解鎖屏幕需要密碼、圖案或其他用戶身份識別)。使用callback異步回調(diào)。

說明

從API version 7開始支持,從API version 9開始廢棄。

系統(tǒng)能力: SystemCapability.MiscServices.ScreenLock

參數(shù):

參數(shù)名

類型

必填

說明

callback

AsyncCallback<boolean>

回調(diào)函數(shù)。返回true表示當前設(shè)備的屏幕鎖定安全;返回false表示當前設(shè)備的屏幕鎖定不安全。

示例:

  1. screenLock.isSecureMode((err, data)=>{
  2. if (err) {
  3. console.error(`Failed to obtain whether the device is in secure mode, because: ${err.message}`);
  4. return;
  5. }
  6. console.info(`Obtain whether the device is in secure mode successfully. result: ${data}`);
  7. });

screenLock.isSecureMode(deprecated)

isSecureMode(): Promise<boolean>

判斷當前設(shè)備的屏幕鎖定是否安全(安全屏幕鎖定意味著解鎖屏幕需要密碼、圖案或其他用戶身份識別)。使用Promise異步回調(diào)。

說明

從API version 7開始支持,從API version 9開始廢棄。

系統(tǒng)能力: SystemCapability.MiscServices.ScreenLock

返回值:

類型

說明

Promise<boolean>

Promise對象。返回true表示當前設(shè)備的屏幕鎖定安全;返回false表示當前設(shè)備的屏幕鎖定不安全。

示例:

  1. screenLock.isSecureMode().then((data) => {
  2. console.info(`Obtain whether the device is in secure mode successfully. result: ${data}`);
  3. }).catch((err) => {
  4. console.error(`Failed to obtain whether the device is in secure mode, because: ${err.message}`);
  5. });

screenLock.unlockScreen(deprecated)

unlockScreen(callback: AsyncCallback<void>): void

解鎖屏幕。使用callback異步回調(diào)。

說明

從API version 7開始支持,從API version 9開始廢棄。

系統(tǒng)能力: SystemCapability.MiscServices.ScreenLock

參數(shù):

參數(shù)名

類型

必填

說明

callback

AsyncCallback<void>

回調(diào)函數(shù)。解鎖屏幕成功,err為undefined,否則為錯誤對象。

示例:

  1. screenLock.unlockScreen((err) => {
  2. if (err) {
  3. console.error(`Failed to unlock the screen, Code: ${err.code}, message: ${err.message}`);
  4. return;
  5. }
  6. console.info('unlock the screen successfully.');
  7. });

screenLock.unlockScreen(deprecated)

unlockScreen(): Promise<void>

解鎖屏幕。使用Promise異步回調(diào)。

說明

從API version 7開始支持,從API version 9開始廢棄。

系統(tǒng)能力: SystemCapability.MiscServices.ScreenLock

返回值:

類型

說明

Promise<void>

Promise對象。無返回結(jié)果的Promise對象。

示例:

  1. screenLock.unlockScreen().then(() => {
  2. console.info('unlock the screen successfully.');
  3. }).catch((err) => {
  4. console.error(`Failed to unlock the screen, Code: ${err.code}, message: ${err.message}`);
  5. });
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號