我想获得安装在Android手机中的所有应用的列表。通过以下代码,我只能获得用户安装的应用程序,但我也想获得系统应用程序。
packageManager = getPackageManager();
List<PackageInfo> packageList = packageManager.getInstalledPackages(packageManager.GET_PERMISSIONS);//PackageManager.GET_META_DATA
List<PackageInfo> packageList1 = new ArrayList<PackageInfo>();
PackageManager pm = this.getPackageManager();
/*To filter out System apps*/
for(PackageInfo pi : packageList) {
boolean b = isSystemPackage(pi);
if(!b) {
packageList1.add(pi);
}
}
apkList = (ListView) findViewById(R.id.AppList);
apkList.setAdapter(new ApkAdapter(this, packageList1, packageManager));
apkList.setOnItemClickListener(this);
}
private boolean isSystemPackage(PackageInfo pkgInfo) {
return ((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ? true
: false;
}
答案 0 :(得分:0)
试试这个:
final PackageManager pm = getActivity().getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> apps = pm.queryIntentActivities(intent, PackageManager.GET_META_DATA);
希望它会帮助你......!