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

The following examples show how to use com.google.android.gms.common.GoogleApiAvailability#isGooglePlayServicesAvailable() . 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 pusher-websocket-android with MIT License 6 votes vote down vote up
private boolean checkPlayServices() {
/**
 * 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.
 */
    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.");
            finish();
        }
        return false;
    }
    return true;
}
 
Example 2
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 3
Source File: Util.java    From Track-My-Location with GNU General Public License v3.0 6 votes vote down vote up
public static boolean checkGooglePlayServicesAvailability(Activity activity) {
    GoogleApiAvailability api = GoogleApiAvailability.getInstance();
    int resultCode = api.isGooglePlayServicesAvailable(activity);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (api.isUserResolvableError(resultCode)) {
            Dialog dialog = api.getErrorDialog(activity, resultCode, 1234);
            dialog.setCancelable(false);
            dialog.setOnCancelListener(dialogInterface -> activity.finish());
            dialog.show();
        } else {
            Toast.makeText(activity, "Device unsupported", Toast.LENGTH_LONG).show();
            activity.finish();
        }

        return false;
    }

    return true;
}
 
Example 4
Source File: LocationEditTextPreference.java    From Advanced_Android_Development with Apache License 2.0 6 votes vote down vote up
public LocationEditTextPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.getTheme().obtainStyledAttributes(
            attrs,
            R.styleable.LocationEditTextPreference,
            0, 0);
    try {
        mMinLength = a.getInteger(R.styleable.LocationEditTextPreference_minLength, DEFAULT_MINIMUM_LOCATION_LENGTH);
    } finally {
        a.recycle();
    }

    // Check to see if Google Play services is available. The Place Picker API is available
    // through Google Play services, so if this is false, we'll just carry on as though this
    // feature does not exist. If it is true, however, we can add a widget to our preference.
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(getContext());
    if (resultCode == ConnectionResult.SUCCESS) {
        // Add the get current location widget to our location preference
        setWidgetLayoutResource(R.layout.pref_current_location);
    }
}
 
Example 5
Source File: MapsActivity.java    From Krishi-Seva with MIT License 5 votes vote down vote up
private boolean CheckGooglePlayServices() {
    GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
    int result = googleAPI.isGooglePlayServicesAvailable(this);
    if(result != ConnectionResult.SUCCESS) {
        if(googleAPI.isUserResolvableError(result)) {
            googleAPI.getErrorDialog(this, result,
                    0).show();
        }
        return false;
    }
    return true;
}
 
Example 6
Source File: VerifyOTP.java    From XERUNG 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 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 {
			finish();
		}
		return false;
	}
	return true;
}
 
Example 7
Source File: PlayServicesUtils.java    From android-gradle-java-app-template with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 8
Source File: MainActivity.java    From sensordatacollector with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Zeigt GoogleMaps an mit GPS position
 */
@SuppressLint( "InflateParams" )
public void showGPSAnalyze()
{
    addScreen(Screens.ANALYZE);

    GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
    int result = googleAPI.isGooglePlayServicesAvailable(this);
    if(result != ConnectionResult.SUCCESS) {
        Toast.makeText(getBaseContext(), getString(R.string.analyze_gps_notify), Toast.LENGTH_LONG).show();
        showAnalyze();
        return;
    }

    if(GPSView == null) {
        GPSView = this.getLayoutInflater().inflate(R.layout.googlemaplayout, null);
    }

    setContentView(GPSView);

    final SupportMapFragment map = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

    Collection<CustomCollector> ccs = SensorDataCollectorService.getInstance().getSCM().getCustomCollectors().values();

    for(CustomCollector cc : ccs) {
        if(SensorDataUtil.getSensorType(cc.getType()).equals("TYPE_GPS")) {
            map.getMapAsync((GPSCollector) cc);
            break;
        }
    }
}
 
Example 9
Source File: DeviceUtils.java    From PrivacyStreams with Apache License 2.0 5 votes vote down vote up
/**
 * Check that Google Play services APK is installed and up to date.
 * @return true if Google Play Services is available and up to date on this device, false otherwise.
 */
public static boolean isGooglePlayServicesAvailable(Context context) {
    GoogleApiAvailability apiAvailability =
            GoogleApiAvailability.getInstance();

    final int connectionStatusCode =
            apiAvailability.isGooglePlayServicesAvailable(context);
    return connectionStatusCode == ConnectionResult.SUCCESS;
}
 
Example 10
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 11
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 12
Source File: MainActivity.java    From Camera2Vision with Apache License 2.0 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(MainActivity.this, resultCode, 2404).show();
        }
    }
    return false;
}
 
Example 13
Source File: CompassActivity.java    From MuslimMateAndroid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Function to check google play services
 *
 * @return Found or not
 */
private boolean checkPlayServices() {
    GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
    int result = googleAPI.isGooglePlayServicesAvailable(this);
    if (result != ConnectionResult.SUCCESS) {
        if (googleAPI.isUserResolvableError(result)) {
            googleAPI.getErrorDialog(this, result,
                    1).show();
        }

        return false;
    }

    return true;
}
 
Example 14
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 15
Source File: Manager.java    From react-native-fitness with MIT License 5 votes vote down vote up
private static boolean isGooglePlayServicesAvailable(final Activity activity) {
    GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
    int status = googleApiAvailability.isGooglePlayServicesAvailable(activity);
    if(status != ConnectionResult.SUCCESS) {
        if(googleApiAvailability.isUserResolvableError(status)) {
            googleApiAvailability.getErrorDialog(activity, status, GOOGLE_PLAY_SERVICE_ERROR_DIALOG).show();
        }
        return false;
    }
    return true;
}
 
Example 16
Source File: LocationController.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkPlayServices() {
    if (playServicesAvailable == null) {
        GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
        int resultCode = apiAvailability.isGooglePlayServicesAvailable(ApplicationLoader.applicationContext);
        playServicesAvailable = resultCode == ConnectionResult.SUCCESS;
    }
    return playServicesAvailable;
}
 
Example 17
Source File: CheckupReminders.java    From Crimson with Apache License 2.0 5 votes vote down vote up
/**
 * Attempt to resolve a missing, out-of-date, invalid or disabled Google
 * Play Services installation via a user dialog, if possible.
 */
private void acquireGooglePlayServices() {
    GoogleApiAvailability apiAvailability =
            GoogleApiAvailability.getInstance();
    final int connectionStatusCode =
            apiAvailability.isGooglePlayServicesAvailable(this);
    if (apiAvailability.isUserResolvableError(connectionStatusCode)) {
        showGooglePlayServicesAvailabilityErrorDialog(connectionStatusCode);
    }
}
 
Example 18
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 19
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);
}
 
Example 20
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;
}