@Override public void onCreate() { super.onCreate(); mLocationFinder = PlatformSpecificImplementationFactory.getLastLocationFinder(this, this); Location location = mLocationFinder.getLastBestLocation(MAX_DISTANCE_LIMIT, MAX_TIME_LIMIT); if (location != null) { onLocationChanged(location); } String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); if (!"".equals(provider)) { LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); final boolean networkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); mNoProviderEnabled = !gpsEnabled && !networkEnabled; } // TODO provide own interface for notifying // that no providers are available if (mNoProviderEnabled) { for (LocationListener listener : mListeners) { listener.onProviderDisabled(null); } } }
@Override public void onDestroy() { mLocationFinder.cancel(); super.onDestroy(); }