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

The following examples show how to use com.google.android.gms.common.GoogleApiAvailability#getInstance() . 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: MainActivity.java    From azure-notificationhubs-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() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                    .show();
        } else {
            Log.i(TAG, "This device is not supported by Google Play Services.");
            ToastNotify("This device is not supported by Google Play Services.");
            finish();
        }
        return false;
    }
    return true;
}
 
Example 2
Source File: WhereAmIActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_where_am_i);

  mTextView = findViewById(R.id.myLocationText);

  GoogleApiAvailability availability = GoogleApiAvailability.getInstance();

  int result = availability.isGooglePlayServicesAvailable(this);
  if (result != ConnectionResult.SUCCESS) {
    if (!availability.isUserResolvableError(result)) {
      Toast.makeText(this, ERROR_MSG, Toast.LENGTH_LONG).show();
    }
  }

  mLocationRequest = new LocationRequest()
                       .setInterval(5000)
                       .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
 
Example 3
Source File: EditUserActivity.java    From Pharmacy-Android with GNU General Public License v3.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() {
    final int PLAY_SERVICES_RESOLUTION_REQUEST = 9002;

    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                    .show();
        } else {
            Timber.i("Play services: This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}
 
Example 4
Source File: RecognitionGoogleCloud.java    From Saiy-PS with GNU Affero General Public License v3.0 6 votes vote down vote up
private void showPlayServicesError(final int errorCode) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "showPlayServicesError");
    }

    onError(SpeechRecognizer.ERROR_CLIENT);

    switch (errorCode) {

        case UNRECOVERABLE:
            // TODO
            break;
        default:
            final GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
            apiAvailability.showErrorNotification(mContext, errorCode);
            break;
    }
}
 
Example 5
Source File: OrderListActivity.java    From Pharmacy-Android with GNU General Public License v3.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() {
    final int PLAY_SERVICES_RESOLUTION_REQUEST = 9002;

    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                    .show();
        } else {
            Timber.i("Play services: This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}
 
Example 6
Source File: NearbyAddContactActivity.java    From zom-android-matrix with Apache License 2.0 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)) {
            apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                    .show();
        } else {
            Log.i(LOG_TAG, "This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}
 
Example 7
Source File: MainActivity.java    From android-gcmnetworkmanager with Apache License 2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example 8
Source File: SettingsFragment.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
private boolean checkPlayServices() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(context);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            noPlayServices();
        } else {
            Log.i(TAG, "This device is not supported.");
        }
        return false;
    }
    return true;
}
 
Example 9
Source File: Utils.java    From protrip with MIT License 5 votes vote down vote up
public static boolean isGooglePlayServicesAvailable(Activity activity) {
    GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
    int status = googleApiAvailability.isGooglePlayServicesAvailable(activity);
    if(status != ConnectionResult.SUCCESS) {
        if(googleApiAvailability.isUserResolvableError(status)) {
            //googleApiAvailability.getErrorDialog(activity, status, 2404).show();
        }
        return false;
    }
    return true;
}
 
Example 10
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 11
Source File: ARFilterActivity.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 5 votes vote down vote up
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(ARFilterActivity.this, resultCode, 2404).show();
        }
    }
    return false;
}
 
Example 12
Source File: AppLocationIntentService.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    mGoogleApiAvailability = GoogleApiAvailability.getInstance();
    mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
    mLocationService = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mLocationRequest = LocationRequest.create();
    enableUpdates = true;
    if (!servicesConnected()) {
        if (!mGoogleApiClient.isConnected() || !mGoogleApiClient.isConnecting())
            mGoogleApiClient.connect();
    }
}
 
Example 13
Source File: GooglePlayServices.java    From redalert-android with Apache License 2.0 5 votes vote down vote up
public static boolean isAvailable(Context context) {
    // Get availability checker
    GoogleApiAvailability playServices = GoogleApiAvailability.getInstance();

    // Check whether services are available
    int result = playServices.isGooglePlayServicesAvailable(context);

    // Are we good?
    return result == ConnectionResult.SUCCESS;
}
 
Example 14
Source File: AppLocationActivity.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mGoogleApiAvailability = GoogleApiAvailability.getInstance();
    mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).enableAutoManage(this, new Random().nextInt(Integer.MAX_VALUE), this).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();

    mLocationService = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    mLocationRequest = LocationRequest.create();

    Intent intent = getIntent();
    enableUpdates = intent.getBooleanExtra(AppLocation.REQUEST_UPDATES, true);
}
 
Example 15
Source File: GoogleProviderHandler.java    From capacitor-firebase-auth with MIT License 5 votes vote down vote up
@Override
public void init(CapacitorFirebaseAuth plugin) {
    this.plugin = plugin;

    String[] permissions = Config.getArray(CONFIG_KEY_PREFIX + "permissions.google", new String[0]);

    GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
    int result = googleAPI.isGooglePlayServicesAvailable(this.plugin.getContext());
    if (result == ConnectionResult.SUCCESS) {
        Log.d(GOOGLE_TAG, "Google Api is Available.");
    } else {
        Log.w(GOOGLE_TAG, "Google Api is not Available.");
    }

    GoogleSignInOptions.Builder gsBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(this.plugin.getContext().getString(R.string.default_web_client_id))
            .requestEmail();

    for (String permission : permissions) {
        try {
            gsBuilder.requestScopes(new Scope(permission));
        } catch (Exception e) {
            Log.w(GOOGLE_TAG, String.format("Failure requesting the scope at index %s", permission));
        }
    }

    GoogleSignInOptions gso = gsBuilder.build();
    this.mGoogleSignInClient = GoogleSignIn.getClient(this.plugin.getActivity(), gso);
}
 
Example 16
Source File: GndApplicationModule.java    From ground-android with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
static GoogleApiAvailability googleApiAvailability() {
  return GoogleApiAvailability.getInstance();
}
 
Example 17
Source File: FlavourApplicationModule.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
@Singleton @Provides LoginPreferences provideLoginPreferences() {
  return new LoginPreferences(application, GoogleApiAvailability.getInstance());
}
 
Example 18
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();
}
 
Example 19
Source File: FirebasePushHelper.java    From linphone-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isAvailable(Context context) {
    GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context);
    return resultCode == ConnectionResult.SUCCESS;
}
 
Example 20
Source File: ReactNativeNotificationHubModule.java    From react-native-azurenotificationhub with MIT License 4 votes vote down vote up
@ReactMethod
public void register(ReadableMap config, Promise promise) {
    ReactNativeNotificationHubUtil notificationHubUtil = ReactNativeNotificationHubUtil.getInstance();
    String connectionString = config.getString(KEY_REGISTRATION_CONNECTIONSTRING);
    if (connectionString == null) {
        promise.reject(ERROR_INVALID_ARGUMENTS, ERROR_INVALID_CONNECTION_STRING);
        return;
    }

    String hubName = config.getString(KEY_REGISTRATION_HUBNAME);
    if (hubName == null) {
        promise.reject(ERROR_INVALID_ARGUMENTS, ERROR_INVALID_HUBNAME);
        return;
    }

    String senderID = config.getString(KEY_REGISTRATION_SENDERID);
    if (senderID == null) {
        promise.reject(ERROR_INVALID_ARGUMENTS, ERROR_INVALID_SENDER_ID);
        return;
    }

    String[] tags = null;
    if (config.hasKey(KEY_REGISTRATION_TAGS) && !config.isNull(KEY_REGISTRATION_TAGS)) {
        ReadableArray tagsJson = config.getArray(KEY_REGISTRATION_TAGS);
        tags = new String[tagsJson.size()];
        for (int i = 0; i < tagsJson.size(); ++i) {
            tags[i] = tagsJson.getString(i);
        }
    }

    ReactContext reactContext = getReactApplicationContext();
    notificationHubUtil.setConnectionString(reactContext, connectionString);
    notificationHubUtil.setHubName(reactContext, hubName);
    notificationHubUtil.setSenderID(reactContext, senderID);
    notificationHubUtil.setTemplated(reactContext, false);
    notificationHubUtil.setTags(reactContext, tags);

    if (config.hasKey(KEY_REGISTRATION_CHANNELNAME)) {
        String channelName = config.getString(KEY_REGISTRATION_CHANNELNAME);
        notificationHubUtil.setChannelName(reactContext, channelName);
    }

    if (config.hasKey(KEY_REGISTRATION_CHANNELDESCRIPTION)) {
        String channelDescription = config.getString(KEY_REGISTRATION_CHANNELDESCRIPTION);
        notificationHubUtil.setChannelDescription(reactContext, channelDescription);
    }

    if (config.hasKey(KEY_REGISTRATION_CHANNELIMPORTANCE)) {
        int channelImportance = config.getInt(KEY_REGISTRATION_CHANNELIMPORTANCE);
        notificationHubUtil.setChannelImportance(reactContext, channelImportance);
    }

    if (config.hasKey(KEY_REGISTRATION_CHANNELSHOWBADGE)) {
        boolean channelShowBadge = config.getBoolean(KEY_REGISTRATION_CHANNELSHOWBADGE);
        notificationHubUtil.setChannelShowBadge(reactContext, channelShowBadge);
    }

    if (config.hasKey(KEY_REGISTRATION_CHANNELENABLELIGHTS)) {
        boolean channelEnableLights = config.getBoolean(KEY_REGISTRATION_CHANNELENABLELIGHTS);
        notificationHubUtil.setChannelEnableLights(reactContext, channelEnableLights);
    }

    if (config.hasKey(KEY_REGISTRATION_CHANNELENABLEVIBRATION)) {
        boolean channelEnableVibration = config.getBoolean(KEY_REGISTRATION_CHANNELENABLEVIBRATION);
        notificationHubUtil.setChannelEnableVibration(reactContext, channelEnableVibration);
    }

    String uuid = notificationHubUtil.getUUID(reactContext);
    if (uuid == null) {
        uuid = ReactNativeUtil.genUUID();
        notificationHubUtil.setUUID(reactContext, uuid);
    }

    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(reactContext);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            UiThreadUtil.runOnUiThread(
                    new GoogleApiAvailabilityRunnable(
                            getCurrentActivity(),
                            apiAvailability,
                            resultCode));
            promise.reject(ERROR_PLAY_SERVICES, ERROR_PLAY_SERVICES_DISABLED);
        } else {
            promise.reject(ERROR_PLAY_SERVICES, ERROR_PLAY_SERVICES_UNSUPPORTED);
        }
        return;
    }

    Intent intent = ReactNativeNotificationHubUtil.IntentFactory.createIntent(
            reactContext, ReactNativeRegistrationIntentService.class);
    ReactNativeRegistrationIntentService.enqueueWork(reactContext, intent);

    WritableMap res = Arguments.createMap();
    res.putString(KEY_PROMISE_RESOLVE_UUID, uuid);
    promise.resolve(res);
}