Check if correct Google Play Service available: “Unfortunately application has stopped working”

To check if GooglePlayServices available or not, Use GoogleApiAvailability.isGooglePlayServicesAvailable(), As GooglePlayServicesUtil.isGooglePlayServicesAvailable() deprecated.

public boolean isGooglePlayServicesAvailable(Context context){
    GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context);
    return resultCode == ConnectionResult.SUCCESS;  
}

Update: Check if google play service available, If google play service is not available and error is recoverable then open a dialog to resolve an error.

public boolean isGooglePlayServicesAvailable(Activity activity) {
    GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
    int status = googleApiAvailability.isGooglePlayServicesAvailable(activity);
    if(status != ConnectionResult.SUCCESS) {
        if(googleApiAvailability.isUserResolvableError(status)) {
              googleApiAvailability.getErrorDialog(activity, status, 2404).show();
        }
        return false;
    }
    return true;
}

Leave a Comment