Hi I am integrating location service in my application. And for that I am using Google's fuse location service.
My implementation is as follows :
public class LocationNotifyService extends Service implements
LocationListener,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
protected void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(INTERVAL);
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
//show error dialog if GoolglePlayServices not available
if (isGooglePlayServicesAvailable()) {
createLocationRequest();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
}
}
@Override
public void onConnected(Bundle bundle) {
Log.d(TAG, "onConnected - isConnected ...............: " + mGoogleApiClient.isConnected());
startLocationUpdates();
}
}
What I want to achieve is when my application is running I want to change LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY
to LocationRequest.HIGH_ACCURACY
and when application is in background again change it to PRIORITY_BALANCED_POWER_ACCURACY
. Same thing with update interval also. If application running it should update location frequently and when it is in background it should update after some time.
So in short this is a service, and I want to change fuse location setting while service is running without restarting the service.
I am perfectly getting application is in foreground or in background. Only problem is to switch priority.