RSS订阅 | 匿名投稿
您的位置:网站首页 > FMX > 正文

Delphi XE android判断程序是否在运行

作者:admin 来源: 日期:2015/12/14 22:39:43 人气: 标签:

function SharedActivityManager: JActivityManager;
var
  AService: JObject;
begin
AService := SharedActivityContext.getSystemService(TJContext.JavaClass.ACTIVITY_SERVICE);
Result := TJActivityManager.Wrap((AService as ILocalObject).GetObjectID);
end;

function IsAppActive(AName:JString):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)or (AProcess.importance=TJActivityManager_RunningAppProcessInfo.JavaClass.IMPORTANCE_BACKGROUND) then
            begin
            Result:=True;
            Break;
            end;
         end;
      end;
    end;
end;

procedure TformMain.Button2Click(Sender: TObject);
var
  b:Boolean;
begin
  b:= IsAppActive(StringToJString(txtfind.Text));
  if b then
    ShowMessage('存在')
    else
    ShowMessage('不存在');
end;

读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址: