Get information about all apps

		//Get the manager of the package
		PackageManager manager=context.getPackageManager();
<span style="white-space:pre"> </span>//Get the information collection of all programs
		List<PackageInfo> installedPackages = manager.getInstalledPackages(0);
<span style="white-space:pre"> </span>//Traverse to get various information
		for(PackageInfo info:installedPackages){
			
			//Get the icon of the application
			Drawable icon = info.applicationInfo.loadIcon(manager);
			// get the application name
			String apkName = info.applicationInfo.loadLabel(manager).toString();
			// package name of the application
			String packageName = info.applicationInfo.packageName;
			//Get the path to the apk resource
			String sourceDir = info.applicationInfo.sourceDir;
			
			File file=new File(sourceDir);
			//apk size
			long apkSize=file.length();
			
			//Get the tag to install the application
			int flags=info.applicationInfo.flags;
			/ / Determine whether it is a system application
			if((flags&ApplicationInfo.FLAG_SYSTEM)!=0){
				//represents the system app
				appInfo.setUserApp(false);
			}else{
				//represents the user app
				appInfo.setUserApp(true);
			}
			//Determine whether it is installed on the sd card or not on the phone
			if((flags&ApplicationInfo.FLAG_EXTERNAL_STORAGE)!=0){
				//represented in sd card
				appInfo.setRom(false);
			}else{
				//Indicates in the phone memory
				appInfo.setRom(true);
			}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325389386&siteId=291194637