2 annbnncnnd AnnBnnCnnD 于 2013.03.20 11:14 提问

名字已知获取activity的ResolveInfo对象

我想添加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个回答

Kakalapa1986
Kakalapa1986   2013.03.20 15:26
已采纳

使用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);
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!