Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if Facebook is installed Android

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?

like image 291
easycheese Avatar asked Jul 15 '11 18:07

easycheese


People also ask

How do I know if an app is installed Android?

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);

Is Facebook installed on my phone?

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.

Where is Facebook on my Android phone?

Tap "Menu" from the home screen, then touch "Facebook." Use the on-screen keypad to enter your login information for Facebook. Tap "Sign In."

How to check if Facebook app is installed or not?

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 -

How do I know if my Facebook tracking pixel is installed?

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.

How do I know if my Facebook pixel status is active?

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.

Can Facebook track you if you're not logged into Facebook?

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.


4 Answers

com.facebook.android is the package name for the Facebook SDK. The Facebook app's package is com.facebook.katana.

like image 130
Torid Avatar answered Oct 09 '22 02:10

Torid


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
              }
          }
    
like image 38
N.Droid Avatar answered Oct 09 '22 03:10

N.Droid


 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;
            }
        }
like image 3
Sanjay Mangaroliya Avatar answered Oct 09 '22 02:10

Sanjay Mangaroliya


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

like image 1
yubaraj poudel Avatar answered Oct 09 '22 02:10

yubaraj poudel