当前位置:   article > 正文

查找mainActivity名称_app 查看main activy

app 查看main activy

通过context查询AndroidManifest.xml内已标记的main_name
突然有了这个需求,那么就动手

public static String[] getMainActivityString(Context c) {
        //通过context获取mainActivity名称
        //如果存在多个main
        try {
            StringBuffer ies = new StringBuffer();
            PackageManager pm = c.getPackageManager();
            String name = c.getPackageName();
            PackageInfo info = pm.getPackageInfo(name, PackageManager.GET_ACTIVITIES);
            ActivityManager manager= (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
            Intent intent = manager.getRunningTasks(1).get(0).baseIntent;
            if (intent == null || info == null) {return null;}
            ActivityInfo[] act = info.activities;
            if (act == null) {return null;}
            for (int i=0;i < act.length;i++) {
                String ie = act[i].name;
                String sub = ie.substring(name.length(), ie.length());
                if (intent.toString().contains(sub)) {
                    ies.append(ie);
                    ies.append(",");
                    //获取栈内intent信息,对比info内的所有
                }
            }
            return ies.toString().split(",");//返回组,分割字符
        } catch (Exception e) {
            return null;
        }
	}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/288787
推荐阅读
相关标签
  

闽ICP备14008679号