protected boolean readyToGo() { GoogleApiAvailability checker= GoogleApiAvailability.getInstance(); int status=checker.isGooglePlayServicesAvailable(this); if (status == ConnectionResult.SUCCESS) { if (getVersionFromPackageManager(this)>=2) { return(true); } else { Toast.makeText(this, R.string.no_maps, Toast.LENGTH_LONG).show(); finish(); } } else if (checker.isUserResolvableError(status)) { ErrorDialogFragment.newInstance(status) .show(getFragmentManager(), TAG_ERROR_DIALOG_FRAGMENT); } else { Toast.makeText(this, R.string.no_maps, Toast.LENGTH_LONG).show(); finish(); } return(false); }
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle args=getArguments(); GoogleApiAvailability checker= GoogleApiAvailability.getInstance(); return(checker.getErrorDialog(getActivity(), args.getInt(ARG_ERROR_CODE), 0)); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.legal); TextView legal=(TextView)findViewById(R.id.legal); legal.setText( GoogleApiAvailability .getInstance() .getOpenSourceSoftwareLicenseInfo(this)); } }
/** * 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() throws SecurityException { // 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; } } }
private boolean checkGooglePlayAvailability() { GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance(); int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context); if(resultCode == ConnectionResult.SUCCESS) { return true; } else { if(googleApiAvailability.isUserResolvableError(resultCode)) { googleApiAvailability.getErrorDialog(MainActivity.this, resultCode, 2404).show(); } } return false; }
public static boolean isGcmApiSupported(Context context) { try { if (!checkedServiceEnabled) { checkedServiceEnabled = true; setServiceEnabled(context, GCM_IN_CLASSPATH); } return GCM_IN_CLASSPATH && GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS && isGcmServiceRegistered(context) == ConnectionResult.SUCCESS; } catch (Throwable t) { // seeing sometimes a DeadObjectException, return false, we can't do anything in this case // still sometimes seeing a NoClassDefFoundError here if (BuildConfig.DEBUG) { CAT.w(t.getMessage()); } return false; } }
/** * Check if play services are installed and use able. * * @param activity An activity */ public static void checkPlayServices(Activity activity) { final GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance(); int errorCode = apiAvailability.isGooglePlayServicesAvailable(activity); if (errorCode != ConnectionResult.SUCCESS) { if (apiAvailability.isUserResolvableError(errorCode)) { apiAvailability.makeGooglePlayServicesAvailable(activity); } else { Toast.makeText(activity, R.string.push_error_device_not_compatible, Toast.LENGTH_SHORT).show(); } } }
Tracker mTracker = application.getDefaultTracker(); GoogleApiAvailability api = GoogleApiAvailability.getInstance(); int code = api.isGooglePlayServicesAvailable(this); if (code == ConnectionResult.SUCCESS) { Handler waitingTimer = new Handler(); } else if (api.isUserResolvableError(code) && api.showErrorDialogFragment(this, code, REQUEST_GOOGLE_PLAY_SERVICES)) { String str = GoogleApiAvailability.getInstance().getErrorString(code); Toast.makeText(this, str, Toast.LENGTH_LONG).show();
@Test public void setIsUserResolvableError() { //Given an injected user resolvable error flag final ShadowGoogleApiAvailability shadowGoogleApiAvailability = Shadows.shadowOf(GoogleApiAvailability.getInstance()); shadowGoogleApiAvailability.setIsUserResolvableError(true); //When getting the actual flag value final boolean actual = GoogleApiAvailability.getInstance() .isUserResolvableError(ConnectionResult.API_UNAVAILABLE); //Then verify that its equal to true assertThat(actual).isTrue(); }
private void openAutocompleteActivity() { try { // The autocomplete activity requires Google Play Services to be available. The intent // builder checks this and throws an exception if it is not the case. Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN) .build(this); startActivityForResult(intent, REQUEST_CODE_AUTOCOMPLETE); } catch (GooglePlayServicesRepairableException e) { // Indicates that Google Play Services is either not installed or not up to date. Prompt // the user to correct the issue. GoogleApiAvailability.getInstance().getErrorDialog(this, e.getConnectionStatusCode(), 0 /* requestCode */).show(); } catch (GooglePlayServicesNotAvailableException e) { // Indicates that Google Play Services is not available and the problem is not easily // resolvable. String message = "Google Play Services is not available: " + GoogleApiAvailability.getInstance().getErrorString(e.errorCode); Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show(); } }
public boolean checkPlayServices() { int resultCode = mGoogleApiAvailability.isGooglePlayServicesAvailable(mContext); if (resultCode != ConnectionResult.SUCCESS) { String errorString = mGoogleApiAvailability.getErrorString(resultCode); if (mGoogleApiAvailability.isUserResolvableError(resultCode)) { Log.w(TAG, errorString); } else { Log.e(TAG, "This device is not supported. " + errorString); } return false; } return true; }
/** * 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; } }
@Test public void getInstance() { //Given the expected GoogleApiAvailability instance final GoogleApiAvailability expected = GoogleApiAvailability.getInstance(); //When getting the actual one from the shadow final GoogleApiAvailability actual = ShadowGoogleApiAvailability.getInstance(); // Then verify that the expected is a not null and equal to the actual one assertThat(expected).isEqualTo(actual); }
private void checkPlayServicesAvailable() { GoogleApiAvailability availability = GoogleApiAvailability.getInstance(); int resultCode = availability.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (availability.isUserResolvableError(resultCode)) { // Show dialog to resolve the error. availability.getErrorDialog(this, resultCode, RC_PLAY_SERVICES).show(); } else { // Unresolvable error Toast.makeText(this, "Google Play Services error", Toast.LENGTH_SHORT).show(); } } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mToken = MusicPlayer.bindToService(this, this); mPlaybackStatus = new PlaybackStatus(this); //make volume keys change multimedia volume even if music is not playing now setVolumeControlStream(AudioManager.STREAM_MUSIC); try { playServicesAvailable = GoogleApiAvailability .getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS; } catch (Exception ignored) { } if (playServicesAvailable) initCast(); }
/** * 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() throws SecurityException { // 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 (cameraSource != null) { try { preview.start(cameraSource, graphicOverlay); } catch (IOException e) { Log.e(TAG, "Unable to start camera source.", e); cameraSource.release(); cameraSource = null; } } }
/** * Invokes whatever external code is necessary to check if the specified error code produced * by {@link #checkGooglePlayServicesAvailable(Context)} represents a user-recoverable error. * Subclasses can override to filter error codes as desired. * @param errorCode The code to check * @return true If the code represents a user-recoverable error */ protected boolean isUserRecoverableError(final int errorCode) { return GoogleApiAvailability.getInstance().isUserResolvableError(errorCode); }
private void openAutocompleteActivity() { try { // The autocomplete activity requires Google Play Services to be available. The intent // builder checks this and throws an exception if it is not the case. Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN) .build(this); startActivityForResult(intent, REQUEST_CODE_AUTOCOMPLETE); } catch (GooglePlayServicesRepairableException e) { // Indicates that Google Play Services is either not installed or not up to date. Prompt // the user to correct the issue. GoogleApiAvailability.getInstance().getErrorDialog(this, e.getConnectionStatusCode(), 0 /* requestCode */).show(); } catch (GooglePlayServicesNotAvailableException e) { // Indicates that Google Play Services is not available and the problem is not easily // resolvable. String message = "Google Play Services is not available: " + GoogleApiAvailability.getInstance().getErrorString(e.errorCode); Log.e(TAG, message); Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.legal); TextView legal=(TextView)findViewById(R.id.legal); legal.setText( GoogleApiAvailability .getInstance() .getOpenSourceSoftwareLicenseInfo(this)); } }
@Test public void shadowOf() { final ShadowGoogleApiAvailability shadowGoogleApiAvailability = Shadows.shadowOf(GoogleApiAvailability.getInstance()); assertThat(shadowGoogleApiAvailability).isNotNull(); }