How to check if Facebook is installed Android
Solution 1:
com.facebook.android
is the package name for the Facebook SDK. The Facebook app's package is com.facebook.katana
.
Solution 2:
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 } }
Solution 3:
if (isAppInstalled()) {
Toast.makeText(getApplicationContext(), "facebook app already installed", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "facebook app not installing", Toast.LENGTH_SHORT).show();
}
public boolean isAppInstalled() {
try {
getApplicationContext().getPackageManager().getApplicationInfo("com.facebook.katana", 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}