Cannot determine whether Google play store is installed or not on Android device
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.
}
TacB0sS
A Java & Android Developer/Architect and a ton of other things as well... Saved you an hour... buy me a coffee :)
Updated on June 06, 2022Comments
-
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 about 12 yearsThat means that now I have to check for the existence of both apps... Hmm... not very nice!
-
Prizoff over 11 yearsBut why do you use flag
PackageManager.GET_UNINSTALLED_PACKAGES
ingetInstalledPackages()
and not justgetInstalledPackages(0)
? -
Prizoff over 11 yearsBy the way, not
"com.google.vending"
, but"com.android.vending"
. Not sure about old name. -
TacB0sS about 11 yearsThis is very recent... I'm about to test it in the next few days... so far the code looks like one big mess!
-
saiyancoder almost 11 yearsIt is indeed! But well, is what Google is used to doing :)
-
Codebeat over 10 yearsThanks, one comment: declaration of packageManager must be: PackageManager packageManager and also want to say the same as Prizoff.
-
Michael about 10 yearsNotice 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 about 10 yearsAbsolutely. Would you like to edit my comment so that it includes this?
-
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 almost 10 yearsGoogle 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 about 8 yearsNote that this requires that you add
com.google.android.gms:play-services-base:$playServicesVersion
to your dependencies. (It doesn't create a run-time dependency on Play Services being installed.) -
Andriy Antonov over 6 years@Thomas, not necessary. you can replace GooglePlayServicesUtil.GOOGLE_PLAY_STORE_PACKAGE with "com.android.vending"
-
user924 over 5 yearsThen 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 over 4 years
isGooglePlayServicesAvailable
is deprecated. UseGoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)
instead.