/** @return the geocoded country code detected by the {@link LocationManager}. */
 private String getLocationBasedCountryIso() {
   if (!Geocoder.isPresent() || !PermissionsUtil.hasLocationPermissions(mContext)) {
     return null;
   }
   final SharedPreferences sharedPreferences =
       PreferenceManager.getDefaultSharedPreferences(mContext);
   return sharedPreferences.getString(KEY_PREFERENCE_CURRENT_COUNTRY, null);
 }
  public static void registerForLocationUpdates(Context context, LocationManager locationManager) {
    if (!PermissionsUtil.hasLocationPermissions(context)) {
      Log.w(TAG, "No location permissions, not registering for location updates.");
      return;
    }

    if (!Geocoder.isPresent()) {
      // Certain devices do not have an implementation of a geocoder - in that case there is
      // no point trying to get location updates because we cannot retrieve the country based
      // on the location anyway.
      return;
    }
    final Intent activeIntent = new Intent(context, LocationChangedReceiver.class);
    final PendingIntent pendingIntent =
        PendingIntent.getBroadcast(context, 0, activeIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    locationManager.requestLocationUpdates(
        LocationManager.PASSIVE_PROVIDER,
        TIME_BETWEEN_UPDATES_MS,
        DISTANCE_BETWEEN_UPDATES_METERS,
        pendingIntent);
  }