权限
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
加上权限才能获取到所有的应用
获取代码
public static boolean hasApplication(Context context, String packageName) {
PackageManager packageManager = context.getPackageManager();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL);
for (int i = 0,count=list.size(); i <count ; i++) {
if(list.get(i).activityInfo.applicationInfo.packageName.equalsIgnoreCase(packageName)) {