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:
boolean myBoolean = googlePlayStoreInstalled(this);
and if you’re in a fragment or so just go
boolean myBoolean = googlePlayStoreInstalled(getActivity());
I keep this in a utility class.
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;
}