简体   繁体   中英

How to catch exception when Google Play Services are not installed and Google Play Store isn't installed also?

I'm making an app that requires Google Play Services for Google maps. The major problem is that when Goole Play services are not Installed, the map fragment shows a message asking the user to install Google Play Services. This is cool but when the user does not have Google Play Store installed, and clicks the "Get Google Play Services" button, the app crashes because nothing handles the intent.

I'm scratching my head trying to know where to catch this exception since the "Google Play Services missing error" is auto-generated. See screenshot below

在此处输入图片说明

Please use this method.

private boolean checkGooglePlayServices() {
            int googlePlayServicesCheck =
                    GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
            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,
                            this, 0);
                    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialogInterface) {
                            finish();
                        }
                    });
                    dialog.show();
                    break;
                default:
            }
            return false;
        }

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