Obtains information about all applications on the mobile phone.

Source: Internet
Author: User

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 ;}}
 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.