Android - How to check if Facebook is installed

This tutorial is will describe to you detail about how to check device have app installed or not yet . please follow it step by step . If you have any question or feedback please list down in comment box.. thank you


Step : 1
Write the function in Utilities Class 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;
        }
    }
Step : 2
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);
                }
SHARE

About Unknown

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment