7

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've checked in PackageInfo and nothing except versionCode and versionName can be of help.

Does anyone know what the first versionCode was or versionName was for Google Play app?

If anyone knows any other way of detecting this let me know.

Ali
  • 12,354
  • 9
  • 54
  • 83
  • I think you're looking for [getApplicationLabel()](http://developer.android.com/reference/android/content/pm/PackageManager.html#getApplicationLabel(android.content.pm.ApplicationInfo)). – adneal Mar 14 '13 at 05:21
  • http://support.google.com/googleplay/bin/answer.py?hl=en-CA&answer=113410 – R KiranKumar Mar 14 '13 at 05:23
  • http://android-er.blogspot.in/2012/12/check-if-correct-google-play-service.html – R KiranKumar Mar 14 '13 at 05:26
  • Thanks guys, I figured out the answer: `packageInfo.applicationInfo.loadLabel(packageManager);` – Ali Mar 14 '13 at 06:13

5 Answers5

5

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.

public static boolean isGooglePlayInstalled(Context context) {
    PackageManager pm = context.getPackageManager();
    boolean app_installed = false;
    try
    {
           PackageInfo info = pm.getPackageInfo("com.android.vending", PackageManager.GET_ACTIVITIES);
           String label = (String) info.applicationInfo.loadLabel(pm);
           app_installed = (label != null && !label.equals("Market"));
    }
    catch (PackageManager.NameNotFoundException e)
    {
           app_installed = false;
    }
    return app_installed;
}
Ali
  • 12,354
  • 9
  • 54
  • 83
  • Do you know what the equivalent for `isAmazonMarketplaceInstalled` would be? Or what the value of `label` would be in the Amazon context? – Alfie Hanssen Oct 25 '13 at 14:18
  • Sorry, don't have a kindle, but if you can figure out the apps package name, that's all you really need. It's going to be `com.amazon.` most likely. I would write a quick test to print out all packages that match `com.amazon.*` and see what the package of the app is. – Ali Oct 31 '13 at 12:17
  • Okay the package name is most likely `com.amazon.venezia`. – Ali Oct 31 '13 at 12:21
2

You can also try this much simplified solution:

public boolean isGooglePlayAvailable() {
        boolean googlePlayStoreInstalled;
        int val= GooglePlayServicesUtil.isGooglePlayServicesAvailable(LocationActivity.this);
        googlePlayStoreInstalled = val == ConnectionResult.SUCCESS;
        return googlePlayStoreInstalled;
    }
Adrian Olar
  • 2,883
  • 4
  • 35
  • 63
  • 2
    This is incorrect. This checks for the Google Play SERVICES and not the Google Play Store "app" to launch market targeted intents. – Ian Jul 28 '16 at 04:53
2

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

    public static boolean isResolveActivity(Intent intent) {
            return App.getInstance().getPackageManager().resolveActivity(intent, PackageManager.GET_RESOLVED_FILTER) != null;
        }

   public void isResolveActivity(String appPackage) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackage));

      if(isResolveActivity(intent)){
      ...open intent
      }
  }
Djek-Grif
  • 1,391
  • 18
  • 18
  • Best answer for me I guess. `com.android.vending` was `com.google.store` before and the other answer depends on a library ... when I only want to know if showing the link makes sense, "trying it out" as in your answer is the best approach. – Giszmo Oct 07 '19 at 14:37
1

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:

public static boolean isPlayStoreInstalled(Context context){
try {
    context.getPackageManager()
            .getPackageInfo(GooglePlayServicesUtil.GOOGLE_PLAY_STORE_PACKAGE, 0);
    return true;
} catch (PackageManager.NameNotFoundException e) {
    return false;
}
}

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

blueware
  • 5,205
  • 1
  • 40
  • 60
0

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:

 public static boolean checkPlayServices(Activity activity) {
        int resultCode = 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();
            }
            return false;
        }
        return true;
    }
scottyab
  • 23,621
  • 16
  • 94
  • 105
  • This is incorrect. This checks for the Google Play SERVICES and not the Google Play Store "app" to launch market targeted intents. – Jared Burrows Oct 18 '16 at 03:39