Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get an activity's ResolveInfo object knowing it's name?

Tags:

java

android

I want to add my activity (com.myapp.launcher.settings) to an empty ArrayList.

    ArrayList<ResolveInfo> selectedApps = new ArrayList<ResolveInfo>();
    selectedApps.add(/*WHAT GOES IN HERE?*/);

But I don't know how to get a ResolveInfo object with my activity.


I managed to make a workaround that loops through all apps to find my activity. But it's not very efficient or practical:

    // 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);
            }
        }
like image 306
lisovaccaro Avatar asked Oct 19 '25 14:10

lisovaccaro


1 Answers

Just use resolveActivity with an explicit Intent. Probably something like this:

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.myapp", "com.myapp.launcher.settings"));
ResolveInfo app = pm.resolveActivity(intent, 0);
selectedApps.add(app);
like image 159
kabuko Avatar answered Oct 21 '25 02:10

kabuko