Skip to content Skip to sidebar Skip to footer

How To Detect If Google Play Is Installed? (not Market)

Whether the app installed is called Google Play or Market, the package name is the same com.android.vending. I need to be able to detect whether the app is Google Play or Market, I

Solution 1:

I figured out how to check the application label. I was using the debugger to see what all was being returned in packageInfo that's why I didn't see it initially.

publicstaticbooleanisGooglePlayInstalled(Context context) {
    PackageManagerpm= context.getPackageManager();
    booleanapp_installed=false;
    try
    {
           PackageInfoinfo= pm.getPackageInfo("com.android.vending", PackageManager.GET_ACTIVITIES);
           Stringlabel= (String) info.applicationInfo.loadLabel(pm);
           app_installed = (label != null && !label.equals("Market"));
    }
    catch (PackageManager.NameNotFoundException e)
    {
           app_installed = false;
    }
    return app_installed;
}

Solution 2:

You can also try this much simplified solution:

publicbooleanisGooglePlayAvailable() {
        boolean googlePlayStoreInstalled;
        int val= GooglePlayServicesUtil.isGooglePlayServicesAvailable(LocationActivity.this);
        googlePlayStoreInstalled = val == ConnectionResult.SUCCESS;
        return googlePlayStoreInstalled;
    }

Solution 3:

In my App I check possibility to open play store before fire it like:

publicstaticbooleanisResolveActivity(Intent intent) {
            returnApp.getInstance().getPackageManager().resolveActivity(intent, PackageManager.GET_RESOLVED_FILTER) != null;
        }

   publicvoidisResolveActivity(String appPackage) {
    Intent intent = newIntent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackage));

      if(isResolveActivity(intent)){
      ...open intent
      }
  }

Solution 4:

You can use this simple piece of code, its easy and to the point with a consideration for not re-inventing the wheel using GooglePlayServicesUtil:

publicstaticbooleanisPlayStoreInstalled(Context context){
try {
    context.getPackageManager()
            .getPackageInfo(GooglePlayServicesUtil.GOOGLE_PLAY_STORE_PACKAGE, 0);
    returntrue;
} catch (PackageManager.NameNotFoundException e) {
    returnfalse;
}
}

This will require you to add this to your dependencies:

compile'com.google.android.gms:play-services-base:[PLAY_SERVICES_VERSION]'

Latest play-services version is now: 10.0.1

Solution 5:

This is probably a better example as it allows for status' where the user can do something about it i.e re-auth or update. Based on the code in the GCM client example project:

publicstaticbooleancheckPlayServices(Activity activity) {
        intresultCode= GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
        if (resultCode != ConnectionResult.SUCCESS) {
            if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
                GooglePlayServicesUtil.getErrorDialog(resultCode, activity,
                        PLAY_SERVICES_RESOLUTION_REQUEST).show();
            } else {
                Toast.makeText(activity.getApplicationContext(), "This device is not supported.", Toast.LENGTH_LONG).show();
                activity.finish();
            }
            returnfalse;
        }
        returntrue;
    }

Post a Comment for "How To Detect If Google Play Is Installed? (not Market)"