Cannot determine whether Google play store is installed or not on Android device

13,994

Solution 1

Be aware that this almost 5 years old code is not optimal and Google does not like when you check all installed packages without no good reason. Please check also the other answers.

The package name has changed, it is now com.android.vending


Try:

private static final String GooglePlayStorePackageNameOld = "com.google.market";
private static final String GooglePlayStorePackageNameNew = "com.android.vending";

void someMethod() {
    PackageManager packageManager = getApplication().getPackageManager();
    List<PackageInfo> packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
    for (PackageInfo packageInfo : packages) {
        if (packageInfo.packageName.equals(GooglePlayStorePackageNameOld) ||
            packageInfo.packageName.equals(GooglePlayStorePackageNameNew)) {
            googlePlayStoreInstalled = true;
            break;
        }
    }
}

Solution 2

GooglePlayServices has a utility class with a method to handle this:

isGooglePlayServicesAvailable(Context).

It provides appropriate error dialogs for the status of play services on the device.

API Reference:

GoogleApiAvailability.isGooglePlayServicesAvailable(android.content.Context)

Solution 3

As Michael stated in the comments Google Play Services is not the same as the Google Play Store. Use this to determine whether or not the Play Store is installed on your device:

public static boolean isPlayStoreInstalled(Context context){
    try {
        context.getPackageManager()
                .getPackageInfo(GooglePlayServicesUtil.GOOGLE_PLAY_STORE_PACKAGE, 0);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

Solution 4

In most case we want to find out whether Google Play Store is installed or not to launch it with some app page preloaded.

Why cant we do this:

final String appPackageName = getPackageName(); // get your app package name
try {
    Uri uri = Uri.parse("market://details?id=" + appPackageName);
    startActivity(new Intent(Intent.ACTION_VIEW, uri));
} catch (android.content.ActivityNotFoundException anfe) {
    // Google Play Store is not available.
}
Share:
13,994
TacB0sS
Author by

TacB0sS

A Java &amp; Android Developer/Architect and a ton of other things as well... Saved you an hour... buy me a coffee :)

Updated on June 06, 2022

Comments

  • TacB0sS
    TacB0sS about 2 years

    This was a simple matter of checking the installed packages on the device... before I've upgraded my OS to 2.3.5, I could locate the Market/Play store, using this code:

    private static final String GooglePlayStorePackageName = "com.google.market";
    
    void someMethod() {
        packageManager = getApplication().getPackageManager();
        List<PackageInfo> packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
        for (PackageInfo packageInfo : packages) {
            if (packageInfo.packageName.equals(GooglePlayStorePackageName)) {
                googlePlayStoreInstalled = true;
                break;
            }
        }
    }
    

    For some reason after the update, I simply cannot find the to package name to indicate the application is installed, although it is on the device, and I can access the market.

    Has the package name changed? or perhaps I'm looking at this the wrong way?

    Thanks,

    Adam.

    UPDATE:

    That was a stupid way to check if a package is installed... a better way is:

    protected final boolean isPackageInstalled(String packageName) {
        try {
            application.getPackageManager().getPackageInfo(packageName, 0);
        } catch (NameNotFoundException e) {
            return false;
        }
        return true;
    }
    
  • TacB0sS
    TacB0sS about 12 years
    That means that now I have to check for the existence of both apps... Hmm... not very nice!
  • Prizoff
    Prizoff over 11 years
    But why do you use flag PackageManager.GET_UNINSTALLED_PACKAGES in getInstalledPackages() and not just getInstalledPackages(0)?
  • Prizoff
    Prizoff over 11 years
    By the way, not "com.google.vending", but "com.android.vending". Not sure about old name.
  • TacB0sS
    TacB0sS about 11 years
    This is very recent... I'm about to test it in the next few days... so far the code looks like one big mess!
  • saiyancoder
    saiyancoder almost 11 years
    It is indeed! But well, is what Google is used to doing :)
  • Codebeat
    Codebeat over 10 years
    Thanks, one comment: declaration of packageManager must be: PackageManager packageManager and also want to say the same as Prizoff.
  • Michael
    Michael about 10 years
    Notice that developers should not confuse the Google Play store app and Google Play Service. GooglePlayServicesUtil.isGooglePlayServicesAvailable() checks for the latter one which might be an indicator but not a requirement. The class has constants for both package names, though. IMHO, if you want to check for an existing Google Play store app (e.g. because you want to launch a market:// intent, use the PackageManager with GOOGLE_PLAY_STORE_PACKAGE.
  • saiyancoder
    saiyancoder about 10 years
    Absolutely. Would you like to edit my comment so that it includes this?
  • rajankz
    rajankz almost 10 years
    @Prizoff: you can disable the Google Play Store App. So while it is not counted in installed apps, it will be picked up when we pass the flag GET_UNINSTALLED_PACKAGES.
  • Michael
    Michael almost 10 years
    Google Play Service != Google Play Store. You can have the store installed but not GPS and vice versa. The OP was asking for the store.
  • Keyur Padalia
    Keyur Padalia about 8 years
    Note that this requires that you add com.google.android.gms:play-services-base:$playServicesVersi‌​on to your dependencies. (It doesn't create a run-time dependency on Play Services being installed.)
  • Andriy Antonov
    Andriy Antonov over 6 years
    @Thomas, not necessary. you can replace GooglePlayServicesUtil.GOOGLE_PLAY_STORE_PACKAGE with "com.android.vending"
  • user924
    user924 over 5 years
    Then why not using this method context.getPackageManager() .getLaunchIntentForPackage("com.google.market") != null || context.getPackageManager() .getLaunchIntentForPackage("com.android.vending") != null)? It doesn't require you to loop through all packages
  • Timo Bähr
    Timo Bähr over 4 years
    isGooglePlayServicesAvailable is deprecated. Use GoogleApiAvailability.getInstance().isGooglePlayServicesAvai‌​lable(context) instead.