赞
踩
通过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; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。