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 xe7 android通过配置实现splash功能

Delphi 对image字段存取图片、文件

Delphi xe webbroker 开发,解决 response 返回中文乱码问题

Delphi生成随机字符串

Delphi 隐藏进程的单元 unit hideprocess.pas

Delphi 用 gdi+ 给图片添加花边的例子

Delphi 顺序查找与二分查找

Delphi tapplication.onexception

一些不常用的且功能相当有用的Delphi函数

Delphi的unicode与gb2312转转换,汉字unicode转gb2312

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



打赏

取消

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

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

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

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

评论

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