delphi xe Android 判断自己程序是否是前台程序


本文整理自网络,侵删。

 

如果程序当前在前台,返回 True,否则返回 False。

 

function IsAppActive:Boolean;

var
  AList:JList;
  AProcess:JActivityManager_RunningAppProcessInfo;
  AName:JString;
  AIterator:JIterator;
begin
AList:=SharedActivityManager.getRunningAppProcesses;
AName:=SharedActivityContext.getPackageName;
Result:=False;
if Assigned(AList) then
  begin
  AIterator:=AList.iterator;
  while AIterator.hasNext do
    begin
    AProcess:=TJActivityManager_RunningAppProcessInfo.Wrap((AIterator.next as ILocalObject).GetObjectID);
    if AProcess.processName.equals(AName) then
      begin
      if AProcess.importance=TJActivityManager_RunningAppProcessInfo.JavaClass.IMPORTANCE_FOREGROUND then
        begin
        Result:=True;
        Break;
        end;
      end;
    end;
  end;
end;

相关阅读 >>

Delphi sendmessage postmessage 原理和区别

Delphi日期函数、日期加减

Delphi 利用tdictionary 文本去重

Delphi用mapfileandchecksum 函数检测 exe 或 dll 是否被修改

Delphi写文本文件

Delphi hmacsha256

Delphi 抓屏技巧

Delphi “invalid floating point operation.”错误的解决方法

Delphi一句话复制整个文件夹(当然包括嵌套文件夹)

Delphi 获取系统服务列表

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



打赏

取消

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

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

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

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

评论

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