[android]代码库
//获取手机中所有已安装的应用,并判断是否系统应用
ArrayList<AppInfo> appList = new ArrayList<AppInfo>(); //用来存储获取的应用信息数据,手机上安装的应用数据都存在appList里
List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);
for(int i = 0; i < packages.size(); i++) {
PackageInfo packageInfo = packages.get(i);
AppInfo tmpInfo = new AppInfo();
tmpInfo.appName = packageInfo.applicationInfo.loadLabel(getPackageManager()).toString();
tmpInfo.packageName = packageInfo.packageName;
tmpInfo.versionName = packageInfo.versionName;
tmpInfo.versionCode = packageInfo.versionCode;
tmpInfo.appIcon = packageInfo.applicationInfo.loadIcon(getPackageManager());
appList.add(tmpInfo);
//判断是否系统应用
if((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
//非系统应用
} else {
//系统应用
}
}
[代码运行效果截图]