Detect if Google Play/Android Market (com.android.vending Package) Is Installed on a Device

It's fairly easy to determine whether there is an app that is registered to handle

market://

requests.

In most cases this will be enough and you can just use the "canHandleMarketURI()" but if you want absolutely make sure that the com.android.vending package is present on the device and is registered to handle the

market://

URIs, then you can simply use "hasGooglePlayMarket()" method.

This method seems to work very well for me.
Enjoy and let me know in the comments if you think this can be further improved.

```java import java.util.List; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; public class GooglePlayRedirector { Context _context; public GooglePlayRedirector(Context c) { _context = c; } /** * Make sure that beside the apps that are registered to handle android market URI, there is the * com.android.vending package, which means that the Google Play app (the Android market) is installed. * * @return */ public boolean hasGooglePlayMarket() { List marketHandlers = getMarketHandlers(); for (ResolveInfo resolveInfo : marketHandlers) { if (resolveInfo.activityInfo.packageName.indexOf("com.android.vending") != -1) { return true; } } //looked through all the handlers for the market://... URI and none were com.android.vending package return false; } /** * Check whether there is any app that is registered to handle android market URIs or not * * @return * - TRUE if someone can handle android market URI, false otherwise */ public boolean canHandleMarketURI() { return getMarketHandlers().size() > 0; } /** * * Pick up all the resolvers for android market URI * * @return * - List of resolvers who can handle the provided URI */ public List getMarketHandlers() { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://search?q=foo")); PackageManager pm = _context.getPackageManager(); List list = pm.queryIntentActivities(intent, 0); return list; } } ```