How to get a list of installed android applications and pick one to run

后端 未结 19 1837
误落风尘
误落风尘 2020-11-21 06:26

I asked a similar question to this earlier this week but I\'m still not understanding how to get a list of all installed applications and then pick one to run.

I\'v

19条回答
  •  礼貌的吻别
    2020-11-21 07:18

    @Jas: I don't have that code anymore, but I've found something close. I've made this to search for "components" of my application, they are just activities with a given category.

    private List getInstalledComponentList() {
        Intent componentSearchIntent = new Intent();
        componentSearchIntent.addCategory(Constants.COMPONENTS_INTENT_CATEGORY);
        componentSearchIntent.setAction(Constants.COMPONENTS_INTENT_ACTION_DEFAULT);
        List ril = getPackageManager().queryIntentActivities(componentSearchIntent, PackageManager.MATCH_DEFAULT_ONLY);
        List componentList = new ArrayList();
        Log.d(LOG_TAG, "Search for installed components found " + ril.size() + " matches.");
        for (ResolveInfo ri : ril) {
            if (ri.activityInfo != null) {
                componentList.add(ri.activityInfo.packageName);// + ri.activityInfo.name);
                Log.d(LOG_TAG, "Found installed: " + componentList.get(componentList.size()-1));
            }
        }
        return componentList;
    }
    

    I've commented the part where it gets the activity name, but it's pretty straightforward.

提交回复
热议问题