mirror of
https://gitlab.com/oeffi/oeffi.git
synced 2025-07-10 19:48:49 +00:00
NearestFavoriteStationWidgetService: Use 'fused' location provider from Google Play Services, if available.
This commit is contained in:
parent
681398598b
commit
56e13aa8cf
1 changed files with 17 additions and 8 deletions
|
@ -60,6 +60,7 @@ import android.location.Criteria;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationListener;
|
import android.location.LocationListener;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
|
import android.location.LocationProvider;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
@ -121,14 +122,22 @@ public class NearestFavoriteStationWidgetService extends JobIntentService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// we want to use as little power as possible
|
log.info("Available location providers: {}", locationManager.getAllProviders());
|
||||||
final Criteria criteria = new Criteria();
|
final String provider;
|
||||||
criteria.setPowerRequirement(Criteria.POWER_LOW);
|
final LocationProvider fused = locationManager.getProvider("fused");
|
||||||
final String provider = locationManager.getBestProvider(criteria, true);
|
if (fused != null) {
|
||||||
if (provider == null || LocationManager.PASSIVE_PROVIDER.equals(provider)) {
|
// prefer fused provider from Google Play Services
|
||||||
widgetsMessage(appWidgetIds, getString(R.string.acquire_location_no_provider));
|
provider = fused.getName();
|
||||||
log.info("No location provider found");
|
} else {
|
||||||
return;
|
// otherwise, we want to use as little power as possible
|
||||||
|
final Criteria criteria = new Criteria();
|
||||||
|
criteria.setPowerRequirement(Criteria.POWER_LOW);
|
||||||
|
provider = locationManager.getBestProvider(criteria, true);
|
||||||
|
if (provider == null || LocationManager.PASSIVE_PROVIDER.equals(provider)) {
|
||||||
|
widgetsMessage(appWidgetIds, getString(R.string.acquire_location_no_provider));
|
||||||
|
log.info("No location provider found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
widgetsHeader(appWidgetIds, getString(R.string.acquire_location_start, provider));
|
widgetsHeader(appWidgetIds, getString(R.string.acquire_location_start, provider));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue