Tabnine Logo
GoogleApiAvailability
Code IndexAdd Tabnine to your IDE (free)

How to use
GoogleApiAvailability
in
com.google.android.gms.common

Best Java code snippets using com.google.android.gms.common.GoogleApiAvailability (Showing top 20 results out of 738)

origin: commonsguy/cw-omnibus

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);
}
origin: commonsguy/cw-omnibus

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
 Bundle args=getArguments();
 GoogleApiAvailability checker=
  GoogleApiAvailability.getInstance();
 return(checker.getErrorDialog(getActivity(),
  args.getInt(ARG_ERROR_CODE), 0));
}
origin: commonsguy/cw-omnibus

 @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));
 }
}
origin: googlesamples/android-vision

/**
 * 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;
    }
  }
}
origin: EzequielAdrianM/Camera2Vision

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;
}
origin: evernote/android-job

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;
  }
}
origin: zendesk/sdk_demo_app_android

/**
 * 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();
    }
  }
}
origin: Phantast/smartnavi

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();
origin: robolectric/robolectric

@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();
}
origin: Sishin/MapLocation

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();
  }
}
origin: Aminoid/react-native-activity-recognition

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;
}
origin: jaredsburrows/android-gradle-java-app-template

  /**
   * 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;
  }
}
origin: robolectric/robolectric

@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);
}
origin: googlesamples/android-gcmnetworkmanager

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();
    }
  }
}
origin: naman14/Timber

@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();
}
origin: googlesamples/android-vision

/**
 * 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;
    }
  }
}
origin: derry/delion

/**
 * 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);
}
origin: googlesamples/android-play-places

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();
  }
}
origin: commonsguy/cw-omnibus

 @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));
 }
}
origin: robolectric/robolectric

@Test
public void shadowOf() {
  final ShadowGoogleApiAvailability shadowGoogleApiAvailability
      = Shadows.shadowOf(GoogleApiAvailability.getInstance());
  assertThat(shadowGoogleApiAvailability).isNotNull();
}
com.google.android.gms.commonGoogleApiAvailability

Most used methods

  • getInstance
  • isGooglePlayServicesAvailable
  • getErrorDialog
  • isUserResolvableError
  • getErrorString
  • getOpenSourceSoftwareLicenseInfo
  • showErrorDialogFragment
  • <init>
  • makeGooglePlayServicesAvailable
  • showErrorNotification

Popular in Java

  • Finding current android device location
  • onRequestPermissionsResult (Fragment)
  • getExternalFilesDir (Context)
  • requestLocationUpdates (LocationManager)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • JFrame (javax.swing)
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now