如果程序当前在前台,返回 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;
|