When does isGooglePlayServicesAvailable return SERVICE_VERSION_UPDATE_REQUIRED?

后端 未结 5 1224
清酒与你
清酒与你 2020-12-17 09:32

According to the documentation GooglePlayServicesUtil.isGooglePlayServicesAvailable returns SERVICE_VERSION_UPDATE_REQUIRED when \"The installed version of Google Play servi

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-17 10:29

    Here are the docs for GooglePlayServicesUtil: http://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesUtil.html.

    Here is where they talking about "ensuring" the user has it installed: https://developer.android.com/google/play-services/setup.html#ensure

    This is taken from the Official Iosched 2014 source code here: https://github.com/google/iosched/blob/0a90bf8e6b90e9226f8c15b34eb7b1e4bf6d632e/android/src/main/java/com/google/samples/apps/iosched/util/PlayServicesUtils.java

    public class PlayServicesUtils {
    
        public static boolean checkGooglePlaySevices(final Activity activity) {
            final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
            switch (googlePlayServicesCheck) {
                case ConnectionResult.SUCCESS:
                    return true;
                case ConnectionResult.SERVICE_DISABLED:
                case ConnectionResult.SERVICE_INVALID:
                case ConnectionResult.SERVICE_MISSING:
                case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
                    Dialog dialog = GooglePlayServicesUtil.getErrorDialog(googlePlayServicesCheck, activity, 0);
                    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialogInterface) {
                            activity.finish();
                        }
                    });
                    dialog.show();
            }
            return false;
        }
    }
    

    Here is how to use it in an Activity: https://github.com/google/iosched/blob/cf1f30b4c752f275518384a9b71404ee501fc473/android/src/main/java/com/google/samples/apps/iosched/ui/BaseActivity.java

    @Override
    protected void onResume() {
        super.onResume();
    
        // Verifies the proper version of Google Play Services exists on the device.
        PlayServicesUtils.checkGooglePlaySevices(this);
    }
    

提交回复
热议问题