Marmoy
Marmoy

Reputation: 8079

How to get ActivityInfo from People/Contacts application from PackageManager?

Part of my application is a launcher, where the user can add (or remove) applications in a Grid. The code that I use to get the ActivityInfo is the following:

Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setAction(Intent.ACTION_MAIN);
intent.setPackage(packageName);
ResolveInfo rInfo = getPackageManager().resolveActivity(intent, 0);

ActivityInfo aInfo = rInfo.activityInfo;

This allows me to extract the Activity icon and label for all other activities and display them in the grid, but in the case of the system Contacts or People application, the extracted icon is the default system icon, and the label is "Android System".

How can I extract the correct activity information for the People application?

Note: The reason I extract activities (resolveActivity()) instead of applications is that some applications define more than one launcher activity and I need to find all activities with category=launcher.

Upvotes: 2

Views: 1734

Answers (1)

Marmoy
Marmoy

Reputation: 8079

I solved it adding the indented line to the code:

Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setAction(Intent.ACTION_MAIN);
intent.setPackage(packageName);
-->intent.setComponent(new ComponentName(packageName, className)));
ResolveInfo rInfo = getPackageManager().resolveActivity(intent, 0);

ActivityInfo aInfo = rInfo.activityInfo;

I extracted the packageName and className from a list of launchable activities I got like this:

private List<ActivityInfo> applications = new ArrayList<ActivityInfo>();

for(ApplicationInfo info:getPackageManager().getInstalledApplications(0)){
    Intent intent = new Intent();
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setAction(Intent.ACTION_MAIN);
    intent.setPackage(info.packageName);
    List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, 0);

    for(ResolveInfo rInfo:list){                
        ActivityInfo activity = rInfo.activityInfo;
        applications.add(activity);
    }
}

Upvotes: 3

Related Questions