Get All Activities by using package Name
Asked Answered
B

1

8

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.

Bangalore answered 15/5, 2014 at 6:51 Comment(5)
ok try this it ll help you.#23669777Jamima
This is i know, it is used to get all applications list. But i want to get all activities names in applicationBangalore
@Leena you mean, you want to get all activities name from one application or from all installed applications?Pedicle
@Leena see my answer, if it should be workful to youPedicle
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.Jamima
B
18

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;
    }
}
Bangalore answered 15/5, 2014 at 7:19 Comment(2)
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 projectWhereupon
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 #6548203.Steck

© 2022 - 2024 — McMap. All rights reserved.