How to know if a particular application is installed or not on the device?

后端 未结 4 1818
我寻月下人不归
我寻月下人不归 2021-01-29 00:56

I want to check whether an app is installed on the device or not. I am using code below :

PackageManager pm = context.getPackageManager();
        List

        
4条回答
  •  礼貌的吻别
    2021-01-29 01:25

    I found the answer here

    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    List pkgAppsList = 
    context.getPackageManager().queryIntentActivities( mainIntent, 0);
    for (ResolveInfo resolveInfo : pkgAppsList) {
                Log.d(TAG, "__<>"+resolveInfo.activityInfo.packageName);
                if (resolveInfo.activityInfo.packageName != null 
                        && resolveInfo.activityInfo.packageName.equals(uri)) {
                  return true;
              }
            }
            return false;
    

    This worked for me perfectly.

提交回复
热议问题