(Android) Check if Google Play Store is installed on device


Here’s a quick way to check if Google Play Store is installed. I use this to keep activities that use in-app billing from crashing on devices that doesn’t have Google Play Store. Works fine in the emulator as well. If the method returns false, I’ll just give the user an alert telling them they need Google Play for in-app billing. If it returns true the in-app billing system gets set up.

Here, implemented in a static method. If you call this from an activity you go:
[java]
boolean myBoolean = googlePlayStoreInstalled(this);
[/java]
and if you’re in a fragment or so just go
[java]
boolean myBoolean = googlePlayStoreInstalled(getActivity());
[/java]

I keep this in a utility class.
[java]
public static boolean googlePlayStoreInstalled(Activity activity) {

PackageManager packageManager = activity.getApplication().getPackageManager();
List<PackageInfo> packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);

for (PackageInfo packageInfo : packages)
if (packageInfo.packageName.equals(GooglePlayStorePackageNameOld) || packageInfo.packageName.equals(GooglePlayStorePackageNameNew))
return true;

return false;
}
[/java]

Leave a Reply

Your email address will not be published. Required fields are marked *