Issue
I want to check that whether whatsapp is installed in mobile or not if installed then show toast "installed" and if not installed then show Toast "Not Installed".How can I do that Kindly help.
Solution
You can use this code. It will check if package is installed.
public class Example extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Put the package name here...
if(isAppInstalled("com.whatsapp")) {
System.out.println("App is already installed on your phone");
} else {
System.out.println("App is not currently installed on your phone");
}
}
private boolean isAppInstalled(String packageName) {
try {
getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
return true;
}
catch (PackageManager.NameNotFoundException ignored) {
return false;
}
}
}
Answered By - Eliasz Kubala
Answer Checked By - Senaida (JavaFixing Volunteer)