The gps is disabled, every so often on android 7 nougat on a Sony Xperia, I'm using the Google merge API. I have a service running in the background.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
buildClient();
if (!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
wakeLock.acquire();
if (scanHandler == null) {
new pro().execute();
}
return Service.START_STICKY;
}
protected synchronized void buildClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
protected void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(scan_interval_ms);
mLocationRequest.setFastestInterval(scan_interval_ms);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
protected void startLocationUpdates() {
createLocationRequest();
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
try {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
Log.v(TAG, "Location update started ..............: ");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
private void removeUpdateLocation()
{
if (mGoogleApiClient.isConnected()){
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}
}
@Override
public void onConnected(@Nullable final Bundle bundle) {
Log.i(TAG, "onConnected - isConnected ...............: " + mGoogleApiClient.isConnected());
if (mGoogleApiClient.isConnected()) {
startLocationUpdates();
}
}
In Android API 23 (6.0) Marshmallow works correctly and in previous versions.
Using the Android API occurs the same (GPS is disabled for the indicated version).