How to detect if Google Play is installed? (Not Market)
Asked Answered
A

5

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.

Atalie answered 14/3, 2013 at 5:17 Comment(4)
I think you're looking for getApplicationLabel().Mightily
support.google.com/googleplay/bin/…Debroahdebs
android-er.blogspot.in/2012/12/…Debroahdebs
Thanks guys, I figured out the answer: packageInfo.applicationInfo.loadLabel(packageManager);Atalie
A
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;
}
Atalie answered 14/3, 2013 at 6:14 Comment(3)
Do you know what the equivalent for isAmazonMarketplaceInstalled would be? Or what the value of label would be in the Amazon context?Semicentennial
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.<something> 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.Atalie
Okay the package name is most likely com.amazon.venezia.Atalie
T
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;
    }
Thelmathem answered 13/11, 2013 at 13:43 Comment(1)
This is incorrect. This checks for the Google Play SERVICES and not the Google Play Store "app" to launch market targeted intents.Lachrymal
C
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
      }
  }
Cattycornered answered 31/12, 2018 at 13:1 Comment(1)
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.Eyrir
U
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

Uela answered 1/2, 2017 at 9:5 Comment(0)
M
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;
    }
Manley answered 21/7, 2014 at 13:56 Comment(1)
This is incorrect. This checks for the Google Play SERVICES and not the Google Play Store "app" to launch market targeted intents.Beaulahbeaulieu

© 2022 - 2024 — McMap. All rights reserved.