我想添加activity(com.myapp.launcher.settings)到空的ArrayList中:ArrayList<ResolveInfo> selectedApps = new ArrayList<ResolveInfo>();
selectedApps.add(/*WHAT GOES IN HERE?*/);但是我不知道怎么获取ResolveInfo对象。我试过使用一个工作环境,将所有的应用循环一遍需找activity,实现之后发现这种方法不是很好用。// Get an array list of all apps
ArrayList<ResolveInfo> allApps = (ArrayList<ResolveInfo>) pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for(final ResolveInfo app : allApps) {
// If it's name is "com.myapp.launcher.settings" add it
if(app.activityInfo.name.equals("com.myapp.launcher.settings")) {
selectedApps.add(app);
}
}
1 回答
心有法竹
TA贡献1866条经验 获得超5个赞
使用resolveActivity
配合显性intent。就可以:
Intent intent = new Intent(); intent.setComponent(new ComponentName("com.myapp", "com.myapp.launcher.settings")); ResolveInfo app = pm.resolveActivity(intent, 0); selectedApps.add(app);
添加回答
举报
0/150
提交
取消