How to check if Facebook is installed Android
To check whether or not an app is installed on Android use this method:
public static boolean isPackageInstalled(Context c, String targetPackage) {
PackageManager pm = c.getPackageManager();
try {
PackageInfo info = pm.getPackageInfo(targetPackage, PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
return false;
}
return true;
}
In your case use any of these packages:
- com.facebook.orca
- com.facebook.katana
- com.example.facebook
- com.facebook.android
boolean hasPackage = isPackageInstalled(MainActivity.this, "com.facebook.katana");
For Kotlin
fun isPackageInstalled(packageName: String, context: Context): Boolean { return try { val packageManager = context.packageManager packageManager.getPackageInfo(packageName, 0) true } catch (e: PackageManager.NameNotFoundException) { false } }
com.facebook.android
is the package name for the Facebook SDK. The Facebook app's package is com.facebook.katana
.