码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-10-12 17:09:53      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:until   job   nec   could   procedure   acl   assigned   exce   proc   

主要解决的问题是:在屏幕处于锁屏或关闭状态下,无法正常显示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;

 

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

标签:until   job   nec   could   procedure   acl   assigned   exce   proc   

原文地址:http://www.cnblogs.com/dannylee/p/7656656.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!