我有这个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&lt; ResolveInfo&gt; (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&lt; ResolveInfo&gt; 或如何转换此for(ResolveInfo mtemp:pkgAppsList)
在德尔福
更新:the size of the list
始终为0,但不可能。可能是什么问题?
答案 0 :(得分: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;