/** * 获取所有的安装的应用程序信息 * * @return */ public static List<AppInfo> getAppInfo(Context context) { // 管理所有apk 的宝PackageManager PackageManager pm = context.getPackageManager(); List<PackageInfo> packageInfos = pm.getInstalledPackages(0); List<AppInfo> appInfos = new ArrayList<AppInfo>(); for (PackageInfo packInfo : packageInfos) { // packinfo 相当于一个应用程序 apk 包的清单文件 AppInfo appInfo = new AppInfo(); String packName = packInfo.packageName; Drawable icon = packInfo.applicationInfo.loadIcon(pm); String name = packInfo.applicationInfo.loadLabel(pm).toString(); int flags = packInfo.applicationInfo.flags; int uid = packInfo.applicationInfo.uid; //流量信息 /* 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.setUserApp(true); } else { // 系统程序 appInfo.setUserApp(false); } if ((flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == 0) { // 手机内存 appInfo.setInRom(true); } else { // 手机外村村设备 appInfo.setInRom(false); } // 适合状态多的 appInfo.setIcon(icon); appInfo.setPackname(packName); appInfo.setName(name); appInfos.add(appInfo); } return appInfos; }