How to list all activities exposed by an application?

前端 未结 4 1444
鱼传尺愫
鱼传尺愫 2020-12-25 07:59

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:<

4条回答
  •  我在风中等你
    2020-12-25 08:30

    If you have the application context then use this:

    private static void listAllActivities(Context context) {
        PackageManager pManager = context.getPackageManager();
        String packageName = 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();
        }
    }
    

提交回复
热议问题