Polarbear0106 Polarbear0106 - 1 year ago 56
Android Question

How can I check if the user has installed an app?

I see apps that offer rewards for downloading an app for an instance, and they know if you have installed the app or not. How do they do that?

Answer Source

define a Method that return true is the PackageManafer can find it:

Example:

 private boolean checkThisApp(String uri) {
        PackageManager myPackageManager = getPackageManager();
        boolean app_installed;
        try {
            myPackageManager.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
            app_installed = true;
        }
        catch (PackageManager.NameNotFoundException e) {
            app_installed = false;
        }
        return app_installed;
    }

and use it in the Activity/Fragment like:

boolean isAppInstalled = checkThisApp("com.facebook.katana");