Locationmanager In Service
Is it possible, to use getSystemService in service? My service class: private LocationManager locationManager; private LocationListener locationListener; IBinder mBinder = new Loc
Solution 1:
Yes of course you can use the LocationManager in a service. for instance I am doing this in the onCreate method of the background service :
public void onCreate() {
mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
String provider = mLocationManager.getBestProvider(criteria, true);
mLocationManager.requestLocationUpdates(provider, LOCATION_UPDATE_INTERVAL_MILLIS, LOCATION_UPDATE_INTERVAL_METERS, this);
}
Post a Comment for "Locationmanager In Service"