7

I want to get all activities present in Application as a list by using PackageInfo. Please tell me is there any way to do this.

Thanks in advance.

Santhi Bharath
  • 2,748
  • 3
  • 25
  • 39
  • ok try this it ll help you.http://stackoverflow.com/questions/23669277/how-to-get-all-homescreens-in-android/23670155#23670155 – Rohit Goswami May 15 '14 at 06:52
  • This is i know, it is used to get all applications list. But i want to get all activities names in application – Santhi Bharath May 15 '14 at 06:58
  • @Leena you mean, you want to get all activities name from one application or from all installed applications? – Pratik Dasa May 15 '14 at 07:00
  • @Leena see my answer, if it should be workful to you – Pratik Dasa May 15 '14 at 07:02
  • ok i got it, please check this method of package manager getPackageArchiveInfo(archiveFilePath, flags); ,here you can Retrieve overall information about an application package defined in a package archive file. and set flag GET_ACTIVITIES. – Rohit Goswami May 15 '14 at 07:04

2 Answers2

16

I got answer to my question as follows.

public static ArrayList<ActivityInfo> getAllRunningActivities(Context context) {
    try {
        PackageInfo pi = context.getPackageManager().getPackageInfo(
                context.getPackageName(), PackageManager.GET_ACTIVITIES);

        return new ArrayList<>(Arrays.asList(pi.activities));

    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
Nikhil
  • 3,661
  • 8
  • 31
  • 43
Santhi Bharath
  • 2,748
  • 3
  • 25
  • 39
1

Try below code:

final PackageManager pm = getPackageManager();

        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        List<ResolveInfo> appList = pm.queryIntentActivities(mainIntent, 0);
        Collections.sort(appList, new ResolveInfo.DisplayNameComparator(pm));

        for (ResolveInfo temp : appList) {

            Log.v("my logs", "package and activity name = "
                    + temp.activityInfo.packageName + "    "
                    + temp.activityInfo.name);


        }
Pratik Dasa
  • 7,389
  • 4
  • 29
  • 44