简体   繁体   中英

how to direct a user to the download page of “Google play services”

My app crashes if a device does not have "Google Play Services" installed in it or if "Google Play Services" in not updated. I want to direct a user to the download page of "Google play Services" if he does not have Play Services installed in his device. I have applied an exception but what should I put in the catch block? I mean how to direct user to the download page of Play Services?

Call GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) to get a status . If the status is not ConnectionResult.SUCCESS , call GooglePlayServicesUtil.isUserRecoverableError(status) -- if that returns true , you should be able to use GooglePlayServicesUtil.getErrorDialog() to display a dialog that will lead the user to download the Play Services Framework.

I think it is too late to answer this, but it could help other people.

Implement this method which check the device to make sure it has the Google Play Services APK, If it doesn't, display a dialog that allows users to download the APK from the Google Play Store or enable it in the device's system settings.

public static boolean checkPlayServices(Activity activity) {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(activity);
    if (resultCode != ConnectionResult.SUCCESS) {
        Log.e("GooglePlayServices", "Google play services not working.");
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(activity, resultCode, 9000)
                    .show();
        } else {
            Log.e("GooglePlayServices", "GCM - This device is not supported.");
        }
        return false;
    }
    return true;
}

Hope it helps someone :)

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