I am modifying my app to be able to catch if a user tries to publish without having the facebook app installed (required for SSO). Here is the code I am using:
try{
ApplicationInfo info = getPackageManager().
getApplicationInfo("com.facebook.android", 0 );
return true;
} catch( PackageManager.NameNotFoundException e ){
return false;
}
The problem is, it is always catching an error. According to the question here, I need to request the appropriate permission but I don't know what permissions I need to request.
Is my problem a permission one or something else?
Call the below function appInstalledOrNot() with the package name of the app installed on the ANDROID Device as a string parameter. This function returns true if the app is installed otherwise returns false. super . onCreate(savedInstanceState);
It is a default app for Android devices. After every update, if you delete it, it will be installed again automatically. There is a list of apps that are preinstalled on the phone. For example, on Android, you usually get from the start all the Google apps, such as YouTube and Gmail app, Facebook and Instagram.
Tap "Menu" from the home screen, then touch "Facebook." Use the on-screen keypad to enter your login information for Facebook. Tap "Sign In."
Best Approach is to pick the package name including com.facebook but anyway you may use following packages: Show activity on this post. You can check it for all Facebook Apps that any of Facebook apps are installed or not . For supporting OS level 11 we need to add this in AndrodiManifest.xml to avoid package name not found exception -
You can search for bits and pieces of your tracking pixel with the CTRL+F keys, or ⌘+F for Mac users, and it will take you to the area in your code where your Facebook tracking pixel is installed successfully. In the code of your site, search for the pixel tracking code.
The simplest option you have is to check the Facebook Ads Manager to see what it says about the pixel status on your website. Note: This isn't a foolproof method that it's working on all of your pages, since Facebook will report it as "Active" if they see it on only one of your pages, so be sure to read on.
It can even track users who aren't logged into Facebook, though it won't be able to tie them to specific Facebook accounts. It's an incredibly powerful tool. Like Google Analytics, to install the Facebook tracking pixel, you need to manually insert the code into your website.
com.facebook.android
is the package name for the Facebook SDK. The Facebook app's package is com.facebook.katana
.
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:
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
}
}
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;
}
}
Write the function in Utilities or anywhere suit for you.This will function will help you to check any app installed or not.let me say for myself it is in Utilities.java
public static boolean isAppInstalled(Context context, String packageName) {
try {
context.getPackageManager().getApplicationInfo(packageName, 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
Then, Call this function from anywhere. for eg to check facebook app
if(Utilities.isAppInstalled(getApplicationContext(), "com.facebook.katana")) {
// Do something
}else {
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.facebook.katana"));
startActivity(i);
}
Enjoy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With