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

The following examples show how to use com.google.android.gms.common.GoogleApiAvailability#getErrorDialog() . 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: Util.java    From Track-My-Location with GNU General Public License v3.0 6 votes vote down vote up
public static boolean checkGooglePlayServicesAvailability(Activity activity) {
    GoogleApiAvailability api = GoogleApiAvailability.getInstance();
    int resultCode = api.isGooglePlayServicesAvailable(activity);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (api.isUserResolvableError(resultCode)) {
            Dialog dialog = api.getErrorDialog(activity, resultCode, 1234);
            dialog.setCancelable(false);
            dialog.setOnCancelListener(dialogInterface -> activity.finish());
            dialog.show();
        } else {
            Toast.makeText(activity, "Device unsupported", Toast.LENGTH_LONG).show();
            activity.finish();
        }

        return false;
    }

    return true;
}
 
Example 2
Source File: LocatrActivity.java    From AndroidProgramming3e with Apache License 2.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int errorCode = apiAvailability.isGooglePlayServicesAvailable(this);

    if (errorCode != ConnectionResult.SUCCESS) {
        Dialog errorDialog = apiAvailability.getErrorDialog(this,
                errorCode,
                REQUEST_ERROR,
                new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialogInterface) {
                        // Leave if services are unavailable.
                        finish();
                    }
                });

        errorDialog.show();
    }
}
 
Example 3
Source File: LocatrActivity.java    From AndroidProgramming3e with Apache License 2.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int errorCode = apiAvailability.isGooglePlayServicesAvailable(this);

    if (errorCode != ConnectionResult.SUCCESS) {
        Dialog errorDialog = apiAvailability.getErrorDialog(this,
                errorCode,
                REQUEST_ERROR,
                new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialogInterface) {
                        // Leave if services are unavailable.
                        finish();
                    }
                });

        errorDialog.show();
    }
}
 
Example 4
Source File: ControllerFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 5 votes vote down vote up
@Override
public void onResume() {
    Log.d(TAG, "onResume");

    super.onResume();

    final Context context = getContext();

    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(context);
    if (resultCode == ConnectionResult.SERVICE_MISSING ||
            resultCode == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED ||
            resultCode == ConnectionResult.SERVICE_DISABLED) {

        Dialog googlePlayErrorDialog = apiAvailability.getErrorDialog(getActivity(), resultCode, MainActivity.kActivityRequestCode_PlayServicesAvailability);
        if (googlePlayErrorDialog != null) {
            googlePlayErrorDialog.show();
        }
    }

    // Setup listeners
    if (context != null) {
        registerEnabledSensorListeners(context, true);
    }

    // Setup send data task
    if (!isSensorPollingEnabled) {
        sendDataHandler.postDelayed(mPeriodicallySendData, kSendDataInterval);
        isSensorPollingEnabled = true;
    }
}
 
Example 5
Source File: NetworkHelper.java    From Bus-Tracking-Parent with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isPlayServicesAvailable(final Activity ctx) {
    GoogleApiAvailability availability = GoogleApiAvailability.getInstance();
    int isAvailable = availability.isGooglePlayServicesAvailable(ctx);
    if (isAvailable == ConnectionResult.SUCCESS) {
        return true;
    } else if (availability.isUserResolvableError(isAvailable)) {
        Dialog dialog = availability.getErrorDialog(ctx, isAvailable, 0);
        dialog.show();
    }else{
        L.err("cant find play services.");
        Toasty.error(ctx,"cant find play services").show();
    }
    return false;
}
 
Example 6
Source File: CheckupReminders.java    From Crimson with Apache License 2.0 5 votes vote down vote up
/**
 * Display an error dialog showing that Google Play Services is missing
 * or out of date.
 *
 * @param connectionStatusCode code describing the presence (or lack of)
 *                             Google Play Services on this device.
 */
void showGooglePlayServicesAvailabilityErrorDialog(
        final int connectionStatusCode) {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    Dialog dialog = apiAvailability.getErrorDialog(
            CheckupReminders.this,
            connectionStatusCode,
            REQUEST_GOOGLE_PLAY_SERVICES);
    dialog.show();
}
 
Example 7
Source File: PlayServicesUtils.java    From android-gradle-java-app-template with Apache License 2.0 5 votes vote down vote up
/**
 * Check if device has the correct Google Play Services version.
 *
 * @param activity     Current activity.
 * @param availability New instance of GoogleApiAvailability.
 * @return True if there was a successful connection ot Google Play Services.
 */
public static boolean hasGooglePlayServices(@NonNull Activity activity, @NonNull GoogleApiAvailability availability) {
    final int result = availability.isGooglePlayServicesAvailable(activity);

    if (result == ConnectionResult.SUCCESS) {
        return true;
    } else {
        final Dialog dialog = availability.getErrorDialog(activity, result, 0);
        // Let user use the application
        dialog.setOnCancelListener(DialogInterface::cancel);
        dialog.show();
    }
    return false;
}
 
Example 8
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 4 votes vote down vote up
private void showGoogleAPIErrorDialog(int errorCode) {
    GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
    Dialog errorDialog = googleApiAvailability.getErrorDialog(
            this, errorCode, REQUEST_RESOLVE_GOOGLE_CLIENT_ERROR);
    errorDialog.show();
}