//得到所有Activity public void getAllActivities(Context context){ try { //第一步:得到PackageName String packageName=context.getPackageName(); //第二步:得到PackageManager PackageManager packageManager=context.getPackageManager(); //第三步:得到PackageInfo PackageInfo packageInfo=packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); //第四步:得到ActivityInfo[] ActivityInfo[] activityInfoList = packageInfo.activities; //第五步:得到每一个Activity for (ActivityInfo activityInfo : activityInfoList) { System.out.println(""+activityInfo.name); } } catch (Exception e) { // TODO: handle exception } }
//得到所有Service private void getAllServices(Context context){ try { // 第一步:得到PackageName String packageName = context.getPackageName(); // 第二步:得到PackageManager PackageManager packageManager = context.getPackageManager(); // 第三步:得到PackageInfo PackageInfo packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SERVICES); // 第四步:得到ServiceInfo[] ServiceInfo[] serviceInfoList = packageInfo.services; // 第五步:得到每一个service for (ServiceInfo serviceInfo : serviceInfoList) { System.out.println("-------> " + serviceInfo.name); } } catch (Exception e) { } }