首页 > 代码库 > 得到所有Activity

得到所有Activity

//得到所有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
		}
		
	}

得到所有Activity