Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get All Activities by using package Name

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.

like image 805
Santhi Bharath Avatar asked May 15 '14 06:05

Santhi Bharath


2 Answers

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;
    }
}
like image 157
Santhi Bharath Avatar answered Nov 20 '22 09:11

Santhi Bharath


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);


        }
like image 20
Pratik Dasa Avatar answered Nov 20 '22 09:11

Pratik Dasa