检查屏幕是否处于锁屏或关闭状态
Posted 竹鹿风清
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了检查屏幕是否处于锁屏或关闭状态相关的知识,希望对你有一定的参考价值。
主要解决的问题是:在屏幕处于锁屏或关闭状态下,无法正常显示MessageDlg
procedure WaitUntilScreenIsActive; begin while True do begin Application.ProcessMessages; if isScreenOn and isKeyguardunLock then Break; end; end; function isScreenOn : Boolean; var Native:JObject ; PowerManager : JPowerManager; begin Native:=SharedActivityContext.getSystemService(TJContext.JavaClass.POWER_SERVICE); if not Assigned(Native) then begin raise Exception.Create(‘Could not locate Connectivity Service‘); end; PowerManager := TJPowerManager.Wrap((Native as ILocalObject).GetObjectID) ; if not Assigned(PowerManager) then Result := True else Result := PowerManager.isScreenOn; Native:=SharedActivityContext.getSystemService(TJContext.JavaClass.KEYGUARD_SERVICE); end; function isKeyguardunLock : Boolean; var Native:JObject ; KeyguardManager : JKeyguardManager; begin Native:=SharedActivityContext.getSystemService(TJContext.JavaClass.KEYGUARD_SERVICE); if not Assigned(Native) then begin raise Exception.Create(‘Could not locate Connectivity Service‘); end; KeyguardManager := TJKeyguardManager.Wrap((Native as ILocalObject).GetObjectID) ; if not Assigned(KeyguardManager) then Result := True else Result := not KeyguardManager.isKeyguardLocked; end;
以上是关于检查屏幕是否处于锁屏或关闭状态的主要内容,如果未能解决你的问题,请参考以下文章