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

后端 未结 4 1814
我寻月下人不归
我寻月下人不归 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:13

    Use Below Code:

    public boolean isAppInstalled(String package_name, String app_name)
    {
        try {
            PackageManager pm = getPackageManager();
            PackageInfo info = pm.getPackageInfo("" + package_name, PackageManager.GET_META_DATA);
            return true;
    
        }
        catch (PackageManager.NameNotFoundException e) {
            Toast.makeText(getApplicationContext(), "Your device has not installed " + app_name, Toast.LENGTH_SHORT)
                    .show();
            return false;
        }
    }
    

    Call the method like:

    isAppInstalled("com.whatsapp", "Whatsapp"); // it will return true if your device is having whatsApp.
    
    isAppInstalled("com.randomname", "anyname"); //it will return false
    

提交回复
热议问题