private static boolean isGooglePlayServicesAvailable(Context context) { return GooglePlayServicesUtil. isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS; } }
@Test public void isGooglePlayServicesAvailable_defaultServiceMissing() { assertEquals(ConnectionResult.SERVICE_MISSING, GooglePlayServicesUtil.isGooglePlayServicesAvailable(RuntimeEnvironment.application)); } }
@Test public void canRedirectStaticMethodToImplementation() { ShadowGooglePlayServicesUtil.provideImpl(mockGooglePlayServicesUtil); when(mockGooglePlayServicesUtil.isGooglePlayServicesAvailable( any(Context.class))).thenReturn(ConnectionResult.INTERNAL_ERROR); assertEquals(ConnectionResult.INTERNAL_ERROR, GooglePlayServicesUtil.isGooglePlayServicesAvailable(RuntimeEnvironment.application)); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mShouldFinishOnStop = false; setContentView(R.layout.activity_sign_in); activityComponent().inject(this); ButterKnife.bind(this); mSignInPresenter.attachView(this); setSignInButtonEnabled(false); int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (resultCode == ConnectionResult.SUCCESS) { setSignInButtonEnabled(true); } else if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { GooglePlayServicesUtil .getErrorDialog(resultCode, this, REQUEST_CODE_PLAY_SERVICES) .show(); } else { showNoPlayServicesError(); Timber.e("This device doesn't support Play Services"); } String popUpMessage = getIntent().getStringExtra(EXTRA_POPUP_MESSAGE); if (popUpMessage != null) { DialogFactory.createSimpleOkErrorDialog(this, popUpMessage).show(); } }
private static boolean checkPlayServices(Activity activity) { int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity); return resultCode == ConnectionResult.SUCCESS || resultCode == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED; // if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { // GooglePlayServicesUtil.getErrorDialog(resultCode, activity, PLAY_SERVICES_RESOLUTION_REQUEST).show(); // } else { // Log.w(TAG, "Unable to install Play Services."); // } }
public static boolean supportsGooglePlayServices(Context context) { return GooglePlayServicesUtil.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS; } }
private boolean isGooglePlayServicesAvailable() { // Check that Google Play services is available int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext); // If Google Play services is available if (ConnectionResult.SUCCESS == resultCode) { // In debug mode, log the status Log.d("Location Updates", "Google Play services is available."); return true; } else { // TODO: Provide feedback when connection unavailable return false; } }
/** * Checks if Google Play services is available. * @return true if it is. */ private boolean isGooglePlayServicesAvailable() { int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (ConnectionResult.SUCCESS == resultCode) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Google Play services is available."); } return true; } else { Log.e(TAG, "Google Play services is unavailable."); return false; } }
private boolean checkPlayServices() { int resultCode = GooglePlayServicesUtil .isGooglePlayServicesAvailable(app); if (resultCode != ConnectionResult.SUCCESS) { if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { GooglePlayServicesUtil.getErrorDialog(resultCode, activity, PLAY_SERVICES_RESOLUTION_REQUEST).show(); } else { Log.i(TAG, "This device is not supported."); } return false; } return true; }
/** * Initializes shared preferences, checks google play services if available, * and register device to GCM server. */ public void init() { mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); LocalBroadcastManager.getInstance(mContext).registerReceiver(mMessageReceiver, new IntentFilter(Constants.INTENT_REGISTRATION_COMPLETE)); int mStatus = GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext); if(mStatus == ConnectionResult.SUCCESS) mContext.startService(new Intent(mContext, RegistrationService.class)); else{ if(mGcmListener != null) mGcmListener.onPlayServiceError(); } }
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; }
/** * Check that Google Play services APK is installed and up to date. */ private boolean checkGooglePlayServicesAvailable() { final int connectionStatusCode = GooglePlayServicesUtil .isGooglePlayServicesAvailable(this); if (GooglePlayServicesUtil.isUserRecoverableError(connectionStatusCode)) { showGooglePlayServicesAvailabilityErrorDialog(connectionStatusCode); return false; } return true; }
private boolean isGooglePlayServicesAvailable() { if(this.playServicesAvailable != null){ return this.playServicesAvailable; } final int connectionStatusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (GooglePlayServicesUtil.isUserRecoverableError(connectionStatusCode)) { showGooglePlayServicesAvailabilityErrorDialog(connectionStatusCode); return this.playServicesAvailable = Boolean.FALSE; } else if (connectionStatusCode != ConnectionResult.SUCCESS ) { return this.playServicesAvailable = Boolean.FALSE; } return this.playServicesAvailable = Boolean.TRUE; }
private boolean isGooglePlayInstalled() { int resultCode = GooglePlayServicesUtil .isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { GooglePlayServicesUtil.getErrorDialog(resultCode, this, ACTION_PLAY_SERVICES_DIALOG).show(); } else { Toast.makeText(getApplicationContext(), "Google Play Service is not installed", Toast.LENGTH_SHORT).show(); finish(); } return false; } return true; }
@Override public void onResume() { Log.d(TAG, "onResume"); super.onResume(); int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (resultCode == ConnectionResult.SERVICE_MISSING || resultCode == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED || resultCode == ConnectionResult.SERVICE_DISABLED) { Dialog googlePlayErrorDialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 0); if (googlePlayErrorDialog != null) { googlePlayErrorDialog.show(); } } // Setup listeners mBleManager.setBleListener(this); registerEnabledSensorListeners(true); // Setup send data task if (!isSensorPollingEnabled) { sendDataHandler.postDelayed(mPeriodicallySendData, kSendDataInterval); isSensorPollingEnabled = true; } }
@Override public void onResume() { MainActivity.info("MAIN: resume."); super.onResume(); // deal with wake lock if (!state.wakeLock.isHeld() && state.screenLocked) { MainActivity.info("acquire wake lock"); state.wakeLock.acquire(); } final int serviceAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); info("GooglePlayServicesAvailable: " + serviceAvailable); if (serviceAvailable != ConnectionResult.SUCCESS && !playServiceShown) { error("service not available! " + serviceAvailable); final Dialog dialog = GooglePlayServicesUtil.getErrorDialog(serviceAvailable, this, 0); dialog.show(); playServiceShown = true; } }
/** * Retrieves a map if the map fragment parameter is null. * <p> * If there is an error tries to solve it checking if it was because of * "Google Play Services" sending the corresponding intent. * * @param mMap map fragment to check if the map is already initialized * @return initialized map fragment */ private GoogleMap retrieveMap(GoogleMap mMap) { // Do a null check to confirm that we have not already instantiated the map. mMapFailed = false; if (mMap == null) { mMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)) .getMap(); // Check if we were successful in obtaining the map. if (mMap == null) { int status = GooglePlayServicesUtil .isGooglePlayServicesAvailable(mApplicationContext); if (status != ConnectionResult.SUCCESS) { enableUIElements(false); Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, getActivity(), OTPApp.CHECK_GOOGLE_PLAY_REQUEST_CODE); dialog.show(); mMapFailed = true; } } } return mMap; }
public static boolean showDialogIfNotAvailable(FragmentActivity activity) { removeDialog(activity); int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity); boolean available = status == ConnectionResult.SUCCESS; if (!available) { if (GooglePlayServicesUtil.isUserRecoverableError(status)) { showDialog(status, activity); } else { ToastHelper.showToast(activity.getApplication(), "Google Play services not available"); } } return available; }
@Override public void onActivityResult (int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 100) { status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()); } if (requestCode == 199) { if (data != null) { place = PlacePicker.getPlace(data, getActivity()); LatLngBounds place2 = PlacePicker.getLatLngBounds(data); String toastMsg = String.format("Place: %s", place.getAddress()+" sfd"+place2.toString()); Toast.makeText(getActivity(), toastMsg, Toast.LENGTH_LONG).show(); textViewAddress.setText(place.getAddress()); storeSharedPreferences.setUserCustomLocation(getActivity(), place.getAddress().toString()); storeSharedPreferences.setUserCoordinates(getActivity(), place.getLatLng().toString()); } else { Toast.makeText(getActivity(), "Select your location", Toast.LENGTH_LONG).show(); } } }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mapView = new MapView(getActivity()); final int serviceAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()); if (serviceAvailable == ConnectionResult.SUCCESS) { try { mapView.onCreate(savedInstanceState); } catch (final SecurityException ex) { MainActivity.error("security exception oncreateview map: " + ex, ex); } } else { WiGLEToast.showOverFragment(this.getActivity(), R.string.fatal_pre_message, getString(R.string.map_needs_playservice)); } MapsInitializer.initialize(getActivity()); final View view = inflater.inflate(R.layout.map, container, false); LatLng oldCenter = null; int oldZoom = Integer.MIN_VALUE; if (state.oldCenter != null) { // pry an orientation change, which calls destroy oldCenter = state.oldCenter; oldZoom = state.oldZoom; } setupMapView(view, oldCenter, oldZoom); return view; }