I want to check whether an app is installed on the device or not. I am using code below :
PackageManager pm = context.getPackageManager();
List
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