Delphi 检查屏幕是否处于锁屏或关闭状态


本文整理自网络,侵删。

 
主要解决的问题是:在屏幕处于锁屏或关闭状态下,无法正常显示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;
来源:https://www.cnblogs.com/dannylee/p/7656656.html
 

相关阅读 >>

Delphi xe6 string转memorystream

Delphi保存读取utf-8的文本文件

Delphi 利用51.la统计程序使用量

Delphi xe7开发的获取网页中字符串的编码是否是utf8

Delphi 外挂编写的几个api函数

Delphi getfiletype 判断图像文件类型

Delphi 中的自动引用计数使用规则

Delphi 获取系统时间,获取系统年月日,时分秒

Delphi环境下基于spcomm控件开发串口通讯报文字节丢失的问题解决

Delphi ttask无法传递参数的一个解决方案

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...