Search code examples
javaandroidandroid-activity

How to get all the activities registered in the operating system of Android?


In my homework I need to get all the activities that are registered to the Android operating system in a list. After that I need to filter them by having category attribute "android.intent.category.LAUNCHER" and action "android.intent.action.MAIN".

I read this question (How to list all activities exposed by an application?) and about Package Manager, but all the methods in the Package Manager only return list of the activities registered to the application package.

As I couldn't find any resource or method saying that I can get all the activities, I'm getting suspicious that I can't do that. Is there any way to perform this kind of action?


Solution

  • The following will give you list of packages category attribute android.intent.category.LAUNCHER and action android.intent.action.MAIN.

    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);
        for (int i = 0; i < pkgAppsList.size(); i++) {
              Log.e("Activity package", pkgAppsList.get(i).activityInfo.name);
         }