1

I created an android photo app and in which I add the functionality of image sharing on facebook,twitter,instagram using intent but when I share the image the app crashes if the facebook,twitter,instagram app was not installed on device.

Pankaj
  • 11
  • 1
  • 11
  • hint : http://stackoverflow.com/questions/6711295/how-to-check-if-facebook-is-installed-android – Farai Sep 09 '14 at 07:51

1 Answers1

6

See this question.It will give you what you want.Just replace the package name with com.facebook.android OR com.facebook.katana

The 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.Ch.Example.pack");  
        if(installed) {
            //This intent will help you to launch if the package is already installed
            Intent LaunchIntent = getPackageManager()
                .getLaunchIntentForPackage("com.facebook.katana");//if this name does not work provide the other one
            startActivity(LaunchIntent);

            System.out.println("App already installed on your phone");        
        }
        else {
            System.out.println("App is not installed on 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
kgandroid
  • 5,507
  • 5
  • 39
  • 69