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,818
  • 3
  • 28
  • 42
  • 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

1 Answers1

17

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,711
  • 8
  • 32
  • 43
Santhi Bharath
  • 2,818
  • 3
  • 28
  • 42
  • 1
    instead of hardcoding the package name like "com.mobeta.android.demodslv" I would use `Context.getPackageName()` to make the code re-usable from project to project – Someone Somewhere Jul 27 '15 at 21:06
  • One should note that this method only returns the enabled/exported activities, not necessarily all listed in the AndroidManifest.xml file. To retrieve all activities, one has to parse the manifest or use aapt, see https://stackoverflow.com/questions/6547703/list-all-activities-within-an-apk-from-the-shell. – auermich Sep 23 '22 at 09:08