1

我有这个java代码:

        final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            final List<ResolveInfo> pkgAppsList = this.getPackageManager().queryIntentActivities( mainIntent, 0);
            ArrayList<String> mIdList=new ArrayList<String>();
            for(ResolveInfo mtemp:pkgAppsList){
                    mIdList.add(mtemp.activityInfo.applicationInfo.packageName);
            }
            Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(mIdList.get(2));
            startActivity( LaunchIntent )

我试图在delphi中使用它,但我不知道如何使用Jlist(在delphi中)而不是List < ResolveInfo >(java),因为函数“queryIntentActivities”的结果是一个JList。

var pm:JPackageManager;
intent:JIntent;
list:jlist;
rinfo:JResolveInfo;
begin
  pm:=SharedActivityContext.getPackageManager;
   intent:=TJIntent.JavaClass.getIntent(TJIntent.JavaClass.ACTION_MAIN);
  intent:= intent.addCategory(TJIntent.JavaClass.CATEGORY_LAUNCHER);
  list:=pm.queryIntentActivities(intent,TJPackageManager.JavaClass.PERMISSION_GRANTED);
 ShowMessage(IntToStr(list.size));

end;

我如何在delphi中使用与Jresolverinfo关联的Jlist?因为在 java 中是这样声明的:List < ResolveInfo > or how I can convert this for(ResolveInfo mtemp:pkgAppsList) in delphi

更新:也the size of the list总是 0 但这是不可能的。可能是什么问题?

4

1 回答 1

2

尝试这样的事情:

var
  PM: JPackageManager;
  mainIntent: JIntent;
  LaunchIntent: JIntent;
  pkgAppsList: JList;
  ri: JResolveInfo;
  iter: JIterator;
  midlist := TStringList;
begin
  PM := SharedActivityContext.getPackageManager;
  mainIntent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_MAIN, nil);
  mainIntent.addCategory(TJIntent.JavaClass.CATEGORY_LAUNCHER);
  pkgAppsList := PM.queryIntentActivities(mainIntent, 0);
  midlist := TStringList;
  iter := pkgAppsList.iterator;
  while iter.hasNext do
  begin
    ri := TJResolveInfo.Wrap((iter.next as ILocalObject).GetObjectID);
    mIdList.Add(ri.activityInfo.applicationInfo.packageName);
  end;
  LaunchIntent := PM.getLaunchIntentForPackage(mIdList[2]);
  SharedActivityContext.startActivity( LaunchIntent )
end;
于 2013-11-12T02:13:42.960 回答