List of all activities in App

会有一股神秘感。 提交于 2019-12-18 03:41:41

问题


Is there any way, how to get list of all activities in running app?

I have tried:

ActivityInfo[] list = getPackageManager().getPackageArchiveInfo(
                    "/sd-ext/app/cz.eman.smartstore.android-1.apk",
                    PackageManager.GET_ACTIVITIES).activities;

but it doesn´t return a list with all of them.


回答1:


If the app is running, then use getPackageInfo(), instead of getPackageArchiveInfo().




回答2:


@CommonsWare had the proper fix. The only thing I want to add for the solution (and would have just commented but you can't format comments properly) is that you don't need to hardcode your package name.

This solution should work:

ActivityInfo[] list = getPackageManager().getPackageInfo(getPackageName()).activities;



回答3:


This code gets list of all the Activities in the application. you can use the same code to get Broadcast Receivers, Services and Content Providers with little editing. Please let me know if there is any way to get the Intent-filters.

public  String getAllActivities(Context context) {
    try {
        String Activities = "";
        PackageInfo pi = context.getPackageManager().getPackageInfo(
                context.getPackageName(), PackageManager.GET_ACTIVITIES);
        if(pi.activities!=null)
        {
        ActivityInfo[] Activities_array = pi.activities;

        for (int i = 0; i < Activities_array.length; i++) {
            int j=i+1;
            Activities  = Activities + j + ") "+ pi.activities[i].name+ ", \n";
        }
        }

        if(Activities.equals(null))
            return "-";
        else 
            return Activities;

    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}`


来源:https://stackoverflow.com/questions/6084716/list-of-all-activities-in-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!