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.
Asked
Active
Viewed 5,134 times
1 Answers
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 ;
}
}