Skip to content Skip to sidebar Skip to footer

How To List All Activities Exposed By An Application?

I think that it should be possible to get all the activities from 'third-party' application, described in the manifest file. I can't figure out how. for example: List

Solution 1:

public ActivityInfo[] getActivityList() throws NameNotFoundException {
    PackageManagerpm=this.getPackageManager();

    PackageInfoinfo= pm.getPackageInfo(getApplicationContext.getPackageName(), PackageManager.GET_ACTIVITIES);
    
    ActivityInfo[] list = info.activities;

    return list;
}

Solution 2:

You should be able to do just that using the PackageManager's getPackageArchiveInfo() using the GET_ACTIVITIES flag. I have not tried it though

Solution 3:

Thanks for the answer!

I think I found a solution for listing all the activities in an application too, not the most elegant though...

//the method gets all activities for an applicationprivatevoidgetAppActivities() {
    PackageManagerpManager= getPackageManager();
    IntentstartIntent= setStartIntent();
    List<ResolveInfo> apps = pManager.queryIntentActivities(startIntent, 0);
    intcount= apps.size();
    for (inti=0; i < count; i++) {
        ResolveInfoinfo= apps.get(i);
        StringpackageName= info.activityInfo.packageName;
        Intentintent=newIntent();
        intent.setPackage(packageName);

        //activities holds the activities defined in the package
        List<ResolveInfo> activities = pManager.queryIntentActivities(intent, 0);
    }
}

Solution 4:

If you have the application context then use this:

privatestaticvoidlistAllActivities(Context context) {
    PackageManagerpManager= context.getPackageManager();
    StringpackageName= context.getApplicationContext().getPackageName();

    try {
        ActivityInfo[] list = pManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES).activities;
        for (ActivityInfo activityInfo : list) {
            Log.d(TAG, "ActivityInfo = " + activityInfo.name);
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}

Post a Comment for "How To List All Activities Exposed By An Application?"