Obtains information about all applications on the mobile phone.
When managing the mobile phone software, we often need to know some basic information about the mobile phone software, such as the type, location, uid, and so on of the application, so that we can perform corresponding operations.
The following is the key code for getting all the software installed on the mobile phone:
/*** Entity class of application information */public class AppInfo {private Drawable icon; private String name; private String packname; private boolean inRom; private boolean userApp; private int uid; public int getUid () {return uid;} public void setUid (int uid) {this. uid = uid;} public Drawable getIcon () {return icon;} public void setIcon (Drawable icon) {this. icon = icon;} public String getName () {return name;} public void setName (String name) {this. name = name;} public String getPackname () {return packname;} public void setPackname (String packname) {this. packname = packname;} public boolean isInRom () {return inRom;} public void setInRom (boolean inRom) {this. inRom = inRom;} public boolean isUserApp () {return userApp;} public void setUserApp (boolean userApp) {this. userApp = userApp ;}@ Overridepublic String toString () {return "AppInfo [name =" + name + ", packname =" + packname + ", inRom =" + inRom + ", userApp = "+ userApp +"] ";}}
/*** Business method: Provides information about all applications installed on your mobile phone */public class AppInfoProvider {/*** to obtain information about all installed applications. * @ Param context Context * @ return */public static List getAppInfos (context) {PackageManager pm = context. getPackageManager (); // information about all application packages installed on the system. List
PackInfos = pm. getInstalledPackages (0); List appInfos = new ArrayList (); for (PackageInfo packInfo: packInfos) {AppInfo appInfo = new AppInfo (); // packInfo is equivalent to the list file String packname = packInfo of an application apk package. packageName; Drawable icon = packInfo. applicationInfo. loadIcon (pm); String name = packInfo. applicationInfo. loadLabel (pm ). toString (); int flags = packInfo. applicationInfo. flags; // The application information mark is equivalent to the user-submitted int uid = PackInfo. applicationInfo. uid; // a fixed number assigned to the application system by the operating system. Once the application is installed with the mobile phone id, it will remain unchanged. // File rcvfile = new File ("/proc/uid_stat/" + uid + "/tcp_rcv "); // File sndfILE = new File ("/proc/uid_stat/" + uid + "/tcp_snd"); appInfo. setUid (uid); if (flags & ApplicationInfo. FLAG_SYSTEM) = 0) {// appInfo of the user program. setUserApp (true);} else {// system program appInfo. setUserApp (false);} if (flags & ApplicationInfo. FLAG_EXTERNAL_STORAGE) = 0) {// memory appInfo of the mobile phone. setInRom (true);} else {// appInfo of the storage device outside the mobile phone. setInRom (false);} appInfo. setPackname (packname); appInfo. setIcon (icon); appInfo. setName (name); appInfos. add (appInfo) ;}return appInfos ;}}