5

I think the question says it all: What is the best way to find out if the user has installed Facebook or Whatsapp on his phone? Do I have to go over the package or what is the best way for this?

Cilenco
  • 6,951
  • 17
  • 72
  • 152
  • Possible duplicate of http://stackoverflow.com/questions/6711295/how-to-check-if-facebook-is-installed-android – woot Jun 28 '13 at 20:31
  • More accurately perhaps duplicate of this: http://stackoverflow.com/questions/11392183/how-to-check-programmatically-if-an-application-is-installed-or-not-in-android – Jonik Jan 28 '15 at 09:39

1 Answers1

12

This was question was answered here. You can using the following piece of code to check for the package name

com.facebook.android OR com.facebook.katana

Code:

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  =   appInstalledOrNot("com.facebook.android");  
            if(installed)
            {
            //This intent will help you to launch if the package is already installed
            Intent LaunchIntent = getPackageManager()
                .getLaunchIntentForPackage("com.facebook.android");
        startActivity(LaunchIntent);


                      System.out.println("App already installed om your phone");


            }
            else
            {
                System.out.println("App is not installed om your phone");
            }
        }
        private boolean appInstalledOrNot(String uri)
        {
            PackageManager pm = getPackageManager();
            boolean app_installed = false;
            try
            {
                   pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
                   app_installed = true;
            }
            catch (PackageManager.NameNotFoundException e)
            {
                   app_installed = false;
            }
            return app_installed ;
    }
    }
Community
  • 1
  • 1
Nick
  • 9,285
  • 33
  • 104
  • 147