2

After updating Google Play Services to version 18, seems that GooglePlayServicesNotAvailableException can't be used anymore. This piece of code:

try {
    MapsInitializer.initialize(ctx);
} catch (GooglePlayServicesNotAvailableException e) {
    e.printStackTrace();
}

generates this error:

Unreachable catch block for GooglePlayServicesNotAvailableException. This exception is never thrown from the try statement body

How can I achieve the same result now? Thanks

Umberto
  • 2,011
  • 1
  • 23
  • 27
  • it is not clear what "same result" you are talking about.Please elaborate – kgandroid Jul 26 '14 at 09:40
  • @kgandroid I want to preserve safe code, catching the exception. – Umberto Jul 26 '14 at 09:44
  • ok...then you can just use catch(Exception e){e.printstacktrace()//or whatever you want to do within catch} – kgandroid Jul 26 '14 at 09:45
  • @kgandroid thanks but I know. The thing I wanted to understand is if I could use another piece of code, consistent with this last version of Google Play Services. Something similar to GooglePlayServicesNotAvailableException. – Umberto Jul 26 '14 at 09:49
  • 1
    you can use this:int checkGooglePlayServices = GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext); if (checkGooglePlayServices != ConnectionResult.SUCCESS) { // google play services is missing!!!! /* Returns status code indicating whether there was an error. Can be one of following in ConnectionResult: SUCCESS, SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, SERVICE_DISABLED, SERVICE_INVALID. */ GooglePlayServicesUtil.getErrorDialog(checkGooglePlayServices, mActivity, 1122).show(); } – kgandroid Jul 26 '14 at 09:52

1 Answers1

5

Now the function initialize() returns a ConnectionResult so you can do something like this:

if (MapsInitializer.initialize(ctx) != ConnectionResult.SUCCESS) {
    // Handle the error
}
user936580
  • 1,223
  • 1
  • 12
  • 19