Java Code Examples for com.google.android.gms.common.ConnectionResult#SUCCESS

The following examples show how to use com.google.android.gms.common.ConnectionResult#SUCCESS . 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: OpenLocate.java    From openlocate-android with MIT License 6 votes vote down vote up
public static OpenLocate initialize(Configuration configuration) {

        saveConfiguration(configuration);

        if (sharedInstance == null) {
            sharedInstance = new OpenLocate(configuration);
        }

        boolean trackingEnabled = SharedPreferenceUtils.getInstance(configuration.context).getBoolanValue(Constants.TRACKING_STATUS, false);

        if (trackingEnabled && hasLocationPermission(configuration.context) &&
                sharedInstance.isGooglePlayServicesAvailable() == ConnectionResult.SUCCESS) {
            sharedInstance.onPermissionsGranted();
        }

        return sharedInstance;
    }
 
Example 2
Source File: PlayServiceManager.java    From android-sdk with MIT License 6 votes vote down vote up
public PlayServiceManager(Context context, LocationHelper location, PermissionChecker checker) {
    this.context = context;
    this.location = location;
    this.checker = checker;
    availability = GoogleApiAvailability.getInstance();
    status = availability.isGooglePlayServicesAvailable(context);
    client = new GoogleApiClient.Builder(context)
            .addConnectionCallbacks(connectionCallbacks)
            .addOnConnectionFailedListener(connectionFailedListener)
            .addApi(LocationServices.API)
            .build();
    if (status != ConnectionResult.SUCCESS) {
        Logger.log.geofenceError("Google Api Client status: " + status + " message: " + availability.getErrorString(status), null);
    }
    handler = new Handler(Looper.getMainLooper());
}
 
Example 3
Source File: MapsActivity.java    From vocefiscal-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() 
{
	int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
	if (resultCode != ConnectionResult.SUCCESS) 
	{
		if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) 
		{
			GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show();
		} else 
		{
			finish();
		}
		return false;
	}
	return true;
}
 
Example 4
Source File: CastUtils.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * A utility method to validate that the appropriate version of the Google Play Services is
 * available on the device. If not, it will open a dialog to address the issue. The dialog
 * displays a localized message about the error and upon user confirmation (by tapping on
 * dialog) will direct them to the Play Store if Google Play services is out of date or missing,
 * or to system settings if Google Play services is disabled on the device.
 */
public static boolean checkGooglePlayServices(final Activity activity) {
  final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
  switch (googlePlayServicesCheck) {
    case ConnectionResult.SUCCESS:
      return true;
    default:
      Dialog dialog = GooglePlayServicesUtil.getErrorDialog(googlePlayServicesCheck, activity, 0);
      dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialogInterface) {
          activity.finish();
        }
      });
      dialog.show();
  }
  return false;
}
 
Example 5
Source File: FaceTrackerActivity.java    From android-vision with Apache License 2.0 6 votes vote down vote up
/**
 * Starts or restarts the camera source, if it exists.  If the camera source doesn't exist yet
 * (e.g., because onResume was called before the camera source was created), this will be called
 * again when the camera source is created.
 */
private void startCameraSource() {

    // check that the device has play services available.
    int code = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(
            getApplicationContext());
    if (code != ConnectionResult.SUCCESS) {
        Dialog dlg =
                GoogleApiAvailability.getInstance().getErrorDialog(this, code, RC_HANDLE_GMS);
        dlg.show();
    }

    if (mCameraSource != null) {
        try {
            mPreview.start(mCameraSource, mGraphicOverlay);
        } catch (IOException e) {
            Log.e(TAG, "Unable to start camera source.", e);
            mCameraSource.release();
            mCameraSource = null;
        }
    }
}
 
Example 6
Source File: RNGoogleSigninModule.java    From google-signin with MIT License 6 votes vote down vote up
@ReactMethod
public void playServicesAvailable(boolean showPlayServicesUpdateDialog, Promise promise) {
    Activity activity = getCurrentActivity();

    if (activity == null) {
        Log.w(MODULE_NAME, "could not determine playServicesAvailable, activity is null");
        promise.reject(MODULE_NAME, "activity is null");
        return;
    }

    GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
    int status = googleApiAvailability.isGooglePlayServicesAvailable(activity);

    if (status != ConnectionResult.SUCCESS) {
        if (showPlayServicesUpdateDialog && googleApiAvailability.isUserResolvableError(status)) {
            int requestCode = 2404;
            googleApiAvailability.getErrorDialog(activity, status, requestCode).show();
        }
        promise.reject(PLAY_SERVICES_NOT_AVAILABLE, "Play services not available");
    } else {
        promise.resolve(true);
    }
}
 
Example 7
Source File: MainActivity.java    From MobileShoppingAssistant-sample with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if Google Play Services are installed and if not it initializes
 * opening the dialog to allow user to install Google Play Services.
 * @return a boolean indicating if the Google Play Services are available.
 */
private boolean checkPlayServices() {
    int resultCode = GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
            GooglePlayServicesUtil.getErrorDialog(resultCode, this,
                    PLAY_SERVICES_RESOLUTION_REQUEST).show();
        } else {
            Log.i(TAG, "This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}
 
Example 8
Source File: ConfigHelper.java    From FORMWatchFace with Apache License 2.0 6 votes vote down vote up
public boolean connect() {
    if (mGoogleApiClient != null) {
        return true;
    }

    if (ConnectionResult.SUCCESS != GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext)
            || Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return false;
    }

    mGoogleApiClient = new GoogleApiClient.Builder(mContext)
            .addApi(Wearable.API)
            .build();
    ConnectionResult connectionResult = mGoogleApiClient.blockingConnect(5, TimeUnit.SECONDS);
    if (!connectionResult.isSuccess()) {
        Log.e(TAG, "Failed to connect to GoogleApiClient: " + connectionResult.getErrorCode());
        mGoogleApiClient = null;
        return false;
    }

    return true;
}
 
Example 9
Source File: ApplicationLoader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkPlayServices() {
    try {
        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        return resultCode == ConnectionResult.SUCCESS;
    } catch (Exception e) {
        FileLog.e(e);
    }
    return true;
}
 
Example 10
Source File: GameHelperUtils.java    From ColorPhun with Apache License 2.0 5 votes vote down vote up
static String errorCodeToString(int errorCode) {
    switch (errorCode) {
        case ConnectionResult.DEVELOPER_ERROR:
            return "DEVELOPER_ERROR(" + errorCode + ")";
        case ConnectionResult.INTERNAL_ERROR:
            return "INTERNAL_ERROR(" + errorCode + ")";
        case ConnectionResult.INVALID_ACCOUNT:
            return "INVALID_ACCOUNT(" + errorCode + ")";
        case ConnectionResult.LICENSE_CHECK_FAILED:
            return "LICENSE_CHECK_FAILED(" + errorCode + ")";
        case ConnectionResult.NETWORK_ERROR:
            return "NETWORK_ERROR(" + errorCode + ")";
        case ConnectionResult.RESOLUTION_REQUIRED:
            return "RESOLUTION_REQUIRED(" + errorCode + ")";
        case ConnectionResult.SERVICE_DISABLED:
            return "SERVICE_DISABLED(" + errorCode + ")";
        case ConnectionResult.SERVICE_INVALID:
            return "SERVICE_INVALID(" + errorCode + ")";
        case ConnectionResult.SERVICE_MISSING:
            return "SERVICE_MISSING(" + errorCode + ")";
        case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
            return "SERVICE_VERSION_UPDATE_REQUIRED(" + errorCode + ")";
        case ConnectionResult.SIGN_IN_REQUIRED:
            return "SIGN_IN_REQUIRED(" + errorCode + ")";
        case ConnectionResult.SUCCESS:
            return "SUCCESS(" + errorCode + ")";
        default:
            return "Unknown error code " + errorCode;
    }
}
 
Example 11
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 12
Source File: FCMRegistrationUtil.java    From product-emm with Apache License 2.0 5 votes vote down vote up
/**
 * Check the device to see if it has Google play services installed. If not
 * prompt user to install.
 *
 * @return if Google play services are installed return true, otherwise false.
 */
public static boolean isPlayServicesInstalled(Context context) {
	GoogleApiAvailability api = GoogleApiAvailability.getInstance();
	int resultCode = api.isGooglePlayServicesAvailable(context);
	if (resultCode != ConnectionResult.SUCCESS) {
		Log.e(TAG, "GCM registration failed, Google play services not available.");
		return false;
	}
	return true;
}
 
Example 13
Source File: FaceAnalyser.java    From Prevent-Screen-Off with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize and start the eye tracking.
 */
void startEyeTracker() {
    //initialize the camera resource
    creteCameraTracker();

    // check that the device has play services available.
    int statusCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(mActivity.getApplicationContext());
    if (statusCode != ConnectionResult.SUCCESS) {
        Dialog dlg = GoogleApiAvailability.getInstance().getErrorDialog(mActivity, statusCode, RC_HANDLE_GMS);
        dlg.show();

        mScreenListener.onErrorOccurred(Errors.PLAY_SERVICE_NOT_AVAILABLE);
        return;
    }

    if (mCameraSource != null) {
        try {
            mPreview.start(mCameraSource);
        } catch (IOException e) {
            Log.e(getClass().getSimpleName(), "Unable to start camera source.", e);
            mCameraSource.release();
            mCameraSource = null;

            mScreenListener.onErrorOccurred(Errors.UNDEFINED);
        }
    }

    isTrackingRunning = true;
    mScreenListener.onScreenMonitoringStart();
}
 
Example 14
Source File: BaseActivity.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onPause() {
	super.onPause();
	boolean googlePlayServicesAvailable = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS;
	if(googlePlayServicesAvailable) {
		mSessionManager.removeSessionManagerListener(mSessionManagerListener);
		mCastSession = null;
	}
}
 
Example 15
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 16
Source File: PlayServicesUtil.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static PlayServicesStatus getPlayServicesStatus(Context context) {
  int gcmStatus = 0;

  try {
    gcmStatus = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
  } catch (Throwable t) {
    Log.w(TAG, t);
    return PlayServicesStatus.MISSING;
  }

  Log.i(TAG, "Play Services: " + gcmStatus);

  switch (gcmStatus) {
    case ConnectionResult.SUCCESS:
      return PlayServicesStatus.SUCCESS;
    case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
      try {
        ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo("com.google.android.gms", 0);

        if (applicationInfo != null && !applicationInfo.enabled) {
          return PlayServicesStatus.MISSING;
        }
      } catch (PackageManager.NameNotFoundException e) {
        Log.w(TAG, e);
      }

      return PlayServicesStatus.NEEDS_UPDATE;
    case ConnectionResult.SERVICE_DISABLED:
    case ConnectionResult.SERVICE_MISSING:
    case ConnectionResult.SERVICE_INVALID:
    case ConnectionResult.API_UNAVAILABLE:
    case ConnectionResult.SERVICE_MISSING_PERMISSION:
      return PlayServicesStatus.MISSING;
    default:
      return PlayServicesStatus.TRANSIENT_ERROR;
  }
}
 
Example 17
Source File: JobScheduler.java    From JobSchedulerCompat with MIT License 4 votes vote down vote up
@RestrictTo(RestrictTo.Scope.LIBRARY)
Scheduler getSchedulerForJob(Context context, JobInfo job) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        return getSchedulerForTag(context, JobSchedulerSchedulerV28.TAG);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        return getSchedulerForTag(context, JobSchedulerSchedulerV26.TAG);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
            && job.getNetworkType() != JobInfo.NETWORK_TYPE_CELLULAR
            && !job.isRequireBatteryNotLow()
            && !job.isRequireStorageNotLow()) {
        return getSchedulerForTag(context, JobSchedulerSchedulerV24.TAG);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
            && (!job.isPeriodic() || job.getFlexMillis() >= job.getIntervalMillis())
            && job.getNetworkType() != JobInfo.NETWORK_TYPE_NOT_ROAMING
            && job.getNetworkType() != JobInfo.NETWORK_TYPE_CELLULAR
            && job.getTriggerContentUris() == null
            && !job.isRequireBatteryNotLow()
            && !job.isRequireStorageNotLow()) {
        return getSchedulerForTag(context, JobSchedulerSchedulerV21.TAG);
    }

    boolean gcmAvailable;
    try {
        gcmAvailable = Class.forName("com.google.android.gms.gcm.GcmNetworkManager") != null
                && GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)
                == ConnectionResult.SUCCESS;
    } catch (Throwable ignored) {
        gcmAvailable = false;
    }
    if (gcmAvailable
            && job.getNetworkType() != JobInfo.NETWORK_TYPE_NOT_ROAMING
            && job.getNetworkType() != JobInfo.NETWORK_TYPE_CELLULAR
            && !job.isRequireBatteryNotLow()
            && !job.isRequireStorageNotLow()) {
        return getSchedulerForTag(context, GcmScheduler.TAG);
    }

    return getSchedulerForTag(context, AlarmScheduler.TAG);
}
 
Example 18
Source File: IsAvailableFunction.java    From face-detection-ane with Apache License 2.0 4 votes vote down vote up
private boolean checkPlayServices( Context context ) {
	GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
	int resultCode = apiAvailability.isGooglePlayServicesAvailable( context );
	return resultCode == ConnectionResult.SUCCESS;
}
 
Example 19
Source File: AdNetworkUtils.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isGooglePlayServicesAvailable(Context context) {
  return GoogleApiAvailability.getInstance()
      .isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS;
}
 
Example 20
Source File: ChatterBoxLogin.java    From pubnub-android-chat with MIT License 2 votes vote down vote up
/**
 * Check if the device supports Google Play Services.  It's best
 * practice to check first rather than handling this as an error case.
 *
 * @return whether the device supports Google Play Services
 */
private boolean supportsGooglePlayServices() {
    Log.d(Constants.LOGT, "google play services available: " + GooglePlayServicesUtil.isGooglePlayServicesAvailable(this));
    return GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) ==
            ConnectionResult.SUCCESS;
}