Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check Whatsapp is installed in device in android?

Tags:

android

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.

like image 910
rahul Avatar asked Apr 05 '16 07:04

rahul


People also ask

How do I know if WhatsApp is installed on Android?

after getting list of packages search for com. whatsapp(package name of whats app given on official webiste Whatsapp). Thats it..

Where is WhatsApp installed in Android?

Open the WhatsApp Messenger app on your Android. You can find it on your home screen or Apps tray.

How do I know when WhatsApp was installed?

The date when your WhatsApp account was made is located in the Terms of Service section.

How do you check the application is installed or not?

Step 1: Open https://play.google.com/store in your web browser. Step 2: Type the name of the app in the search bar to look for the app.


2 Answers

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...
        boolean installed = isAppInstalled("com.whatsapp");  
        if(installed) {
            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) {
        PackageManager pm = getPackageManager();
        boolean app_installed;
        try {
            pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
            app_installed = true;
        }
        catch (PackageManager.NameNotFoundException e) {
            app_installed = false;
        }
        return app_installed;
    }
}
like image 133
Eliasz Kubala Avatar answered Oct 17 '22 05:10

Eliasz Kubala


based on @eliasz-kubala answer this will work for me on Android 11 after only adding this to Manifest

  <manifest 
    ...> 
    <queries> <package android:name="com.whatsapp" /> </queries>
  
    <application ....>
    </application>
  </manifest>

and Then use this Kotlin function

  private fun isAppInstalled(packageName: String): Boolean {
    val pm: PackageManager = getPackageManager()
    return try {
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
        true
    } catch (e: PackageManager.NameNotFoundException) {
        false
    }
   }
like image 27
Sattar Avatar answered Oct 17 '22 05:10

Sattar