Java Code Examples for com.google.android.gms.common.GoogleApiAvailability#isUserResolvableError()

The following examples show how to use com.google.android.gms.common.GoogleApiAvailability#isUserResolvableError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From azure-notificationhubs-android with Apache License 2.0 6 votes vote down vote up
/**
 * 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.
 */

private boolean checkPlayServices() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                    .show();
        } else {
            Log.i(TAG, "This device is not supported by Google Play Services.");
            ToastNotify("This device is not supported by Google Play Services.");
            finish();
        }
        return false;
    }
    return true;
}
 
Example 2
Source File: MainActivity.java    From google-services with Apache License 2.0 6 votes vote down vote up
/**
 * 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.
 */
private boolean checkPlayServices() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                    .show();
        } else {
            Log.i(TAG, "This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}
 
Example 3
Source File: MainActivity.java    From Advanced_Android_Development with Apache License 2.0 6 votes vote down vote up
/**
 * 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.
 */
private boolean checkPlayServices() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(this, resultCode,
                    PLAY_SERVICES_RESOLUTION_REQUEST).show();
        } else {
            Log.i(LOG_TAG, "This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}
 
Example 4
Source File: EditUserActivity.java    From Pharmacy-Android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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.
 */
private boolean checkPlayServices() {
    final int PLAY_SERVICES_RESOLUTION_REQUEST = 9002;

    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                    .show();
        } else {
            Timber.i("Play services: This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}
 
Example 5
Source File: WhereAmIActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_where_am_i);

  mTextView = findViewById(R.id.myLocationText);

  GoogleApiAvailability availability = GoogleApiAvailability.getInstance();

  int result = availability.isGooglePlayServicesAvailable(this);
  if (result != ConnectionResult.SUCCESS) {
    if (!availability.isUserResolvableError(result)) {
      Toast.makeText(this, ERROR_MSG, Toast.LENGTH_LONG).show();
    }
  }
}
 
Example 6
Source File: CompassActivity.java    From MuslimMateAndroid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Function to check google play services
 *
 * @return Found or not
 */
private boolean checkPlayServices() {
    GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
    int result = googleAPI.isGooglePlayServicesAvailable(this);
    if (result != ConnectionResult.SUCCESS) {
        if (googleAPI.isUserResolvableError(result)) {
            googleAPI.getErrorDialog(this, result,
                    1).show();
        }

        return false;
    }

    return true;
}
 
Example 7
Source File: MainActivity.java    From ETSMobile-Android2 with Apache License 2.0 5 votes vote down vote up
/**
 * 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.
 */
private void checkPlayServices() {
    GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (googleApiAvailability.isUserResolvableError(resultCode)) {
            googleApiAvailability.getErrorDialog(this, resultCode,
                    Constants.PLAY_SERVICES_RESOLUTION_REQUEST).show();
        } else {
            Log.i(TAG, "This device is not supported.");
            finish();
        }
    }
}
 
Example 8
Source File: NearbyAddContactActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
private boolean checkPlayServices() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                    .show();
        } else {
            Log.i(TAG, "This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}
 
Example 9
Source File: MapsActivity.java    From Krishi-Seva with MIT License 5 votes vote down vote up
private boolean CheckGooglePlayServices() {
    GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
    int result = googleAPI.isGooglePlayServicesAvailable(this);
    if(result != ConnectionResult.SUCCESS) {
        if(googleAPI.isUserResolvableError(result)) {
            googleAPI.getErrorDialog(this, result,
                    0).show();
        }
        return false;
    }
    return true;
}
 
Example 10
Source File: VerifyOTP.java    From XERUNG with Apache License 2.0 5 votes vote down vote up
/**
 * 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.
 */
private boolean checkPlayServices() {
	GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
	int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
	if (resultCode != ConnectionResult.SUCCESS) {
		if (apiAvailability.isUserResolvableError(resultCode)) {
			apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
					.show();
		} else {
			finish();
		}
		return false;
	}
	return true;
}
 
Example 11
Source File: VerifyOTP.java    From XERUNG with Apache License 2.0 5 votes vote down vote up
/**
 * 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.
 */
private boolean checkPlayServices() {
	GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
	int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
	if (resultCode != ConnectionResult.SUCCESS) {
		if (apiAvailability.isUserResolvableError(resultCode)) {
			apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
					.show();
		} else {
			finish();
		}
		return false;
	}
	return true;
}
 
Example 12
Source File: Utils.java    From protrip with MIT License 5 votes vote down vote up
public static 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;
}
 
Example 13
Source File: DeviceUtils.java    From PrivacyStreams with Apache License 2.0 5 votes vote down vote up
/**
 * Attempt to resolve a missing, out-of-date, invalid or disabled Google
 * Play Services installation via a user dialog, if possible.
 */
public static void acquireGooglePlayServices(Context context) {
    GoogleApiAvailability apiAvailability =
            GoogleApiAvailability.getInstance();
    final int connectionStatusCode =
            apiAvailability.isGooglePlayServicesAvailable(context);
    if (apiAvailability.isUserResolvableError(connectionStatusCode)) {
       Log.e("Error","Connection Status Code"+connectionStatusCode);
    }
}
 
Example 14
Source File: MainActivity.java    From ello-android with MIT License 5 votes vote down vote up
private boolean checkPlayServices() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                    .show();
        } else {
            Log.i(TAG, "This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}
 
Example 15
Source File: WelcomeActivitySign.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
private boolean checkPlayServices() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            noPlayServices();
        } else {
            Cardbar.snackBar(this, "This device is not supported.", true).show();
        }
        return false;
    }
    return true;
}
 
Example 16
Source File: NearbyAddContactActivity.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
private boolean checkPlayServices() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                    .show();
        } else {
            Log.i(LOG_TAG, "This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}
 
Example 17
Source File: AppUtils.java    From SampleApp with Apache License 2.0 5 votes vote down vote up
/**
 * 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 boolean checkPlayServices() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(mContext);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog((Activity) mContext, resultCode, 9000)
                    .show();
        } else {
            showToast(mContext.getResources().getString(R.string.warning_play_services));
        }
        return false;
    }
    return true;
}
 
Example 18
Source File: Manager.java    From react-native-fitness with MIT License 5 votes vote down vote up
private static boolean isGooglePlayServicesAvailable(final Activity activity) {
    GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
    int status = googleApiAvailability.isGooglePlayServicesAvailable(activity);
    if(status != ConnectionResult.SUCCESS) {
        if(googleApiAvailability.isUserResolvableError(status)) {
            googleApiAvailability.getErrorDialog(activity, status, GOOGLE_PLAY_SERVICE_ERROR_DIALOG).show();
        }
        return false;
    }
    return true;
}
 
Example 19
Source File: MainActivity.java    From journaldev with MIT License 5 votes vote down vote up
private boolean checkPlayServices() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                    .show();
        } else
            finish();

        return false;
    }
    return true;
}
 
Example 20
Source File: PlayServicesSupport.java    From mobile-messaging-sdk-android with Apache License 2.0 4 votes vote down vote up
/**
 * 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 void checkPlayServicesAndTryToAcquireToken(final Context context, boolean shouldResetToken, @Nullable MobileMessaging.InitListener initListener) {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int errorCode = apiAvailability.isGooglePlayServicesAvailable(context);
    isPlayServicesAvailable = errorCode == ConnectionResult.SUCCESS;
    if (errorCode != ConnectionResult.SUCCESS) {

        InternalSdkError internalSdkError;
        if (apiAvailability.isUserResolvableError(errorCode)) {
            internalSdkError = InternalSdkError.ERROR_ACCESSING_PLAY_SERVICES;
        } else {
            errorCode = DEVICE_NOT_SUPPORTED;
            internalSdkError = InternalSdkError.DEVICE_NOT_SUPPORTED;
        }

        final int finalErrorCode = errorCode;
        if (initListener != null) {
            initListener.onError(internalSdkError, finalErrorCode);
        }
        MobileMessagingLogger.e(internalSdkError.get() + ". google error code: " + errorCode + ", see com.google.android.gms.common.ConnectionResult");

        // Broadcast is not triggered unless it's posted to Main thread queue. See http://stackoverflow.com/a/23917619/2895571
        handler.post(new Runnable() {
            @Override
            public void run() {
                Intent playServicesError = new Intent(Event.GOOGLE_PLAY_SERVICES_ERROR.getKey());
                playServicesError.putExtra(BroadcastParameter.EXTRA_PLAY_SERVICES_ERROR_CODE, finalErrorCode);

                context.sendBroadcast(playServicesError);
                LocalBroadcastManager.getInstance(context).sendBroadcast(playServicesError);
                handler.removeCallbacksAndMessages(null);
            }
        });
        return;
    }

    String senderId = MobileMessagingCore.getSenderId(context);
    if (shouldResetToken) {
        MobileMessagingCloudService.enqueueTokenReset(context, senderId);
    } else {
        MobileMessagingCloudService.enqueueTokenAcquisition(context, senderId);
    }

    if (initListener != null) {
        initListener.onSuccess();
    }
}