简体   繁体   中英

How to check if an android device has Google Play installed?

I am trying to check if the device has Google Play installed or not in my app, but seems there is no way to do that. I followed the post HERE but still doesn't work, always return true even i was testing with an emulator, it has com.android.vending installed. So am i checking the wrong package name? Any ideas for that?

Thanks in advance!

Follow Dcoumentation to check if the device has Google Play Service available.

In Short, simply:

// Getting status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

// Showing status
if(status==ConnectionResult.SUCCESS)
//Google Play Services are available
else{
//Google Play Services are not available
}

Hope this will help you :)

Finally, found a way to check Google Play installed, here is the code:

public static boolean isPackageInstalled(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 = (!TextUtils.isEmpty(label) && label.startsWith("Google Play"));
    } catch(PackageManager.NameNotFoundException e) {
       app_installed = false;
    }
    return app_installed;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM