Diana
Diana

Reputation: 75

Check if Activity is Launcher from ActivityInfo/PackageManager

I need to check if an installed app has a specific launcher activity class (based on the package name of the app).

I can get the list of activities and find the correct class with this:

PackageInfo info = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);

for (ActivityInfo a : info.activities) {
    if (a.name.compareTo("specific class name") == 0)

        // if a is launcher activity
            return true;
    }

But I can't seem to find any way to check if the activity is actually the launcher.

Is there any way to get the information about the intent filters associated with the activity from the manifest file?

Upvotes: 2

Views: 2721

Answers (2)

winubmac1024
winubmac1024

Reputation: 63

You can check if an app has a launcher activity using this:

(context.packageManager.getLaunchIntentForPackage(app_package_name) != null)

Upvotes: 2

Devendra B. Singh
Devendra B. Singh

Reputation: 304

Get the list of launcher activity from all apps like below

        final PackageManager pm = getPackageManager();
        // package manager is provider of all the application information
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        List<ResolveInfo> appList = pm.queryIntentActivities(mainIntent, 0);

        for (ResolveInfo info : appList) {

            Log.d("package and activity name = "
                    + info.activityInfo.packageName + "    "
                    + info.activityInfo.name);


        }

Upvotes: 2

Related Questions