Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'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.

like image 866
Ali Avatar asked Mar 14 '13 05:03

Ali


2 Answers

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;
}
like image 160
Ali Avatar answered Oct 29 '22 15:10

Ali


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;
    }
like image 42
Adrian Olar Avatar answered Oct 29 '22 16:10

Adrian Olar