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.
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;
}
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With