Fix issue with background service
This commit is contained in:
parent
496103c263
commit
7c3ff2d5cb
3 changed files with 39 additions and 32 deletions
|
@ -200,8 +200,6 @@ public class NavigationService extends Service implements LocationListener {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderDisabled(String provider) {
|
public void onProviderDisabled(String provider) {
|
||||||
Toast.makeText(this, getString(R.string.off_router_service_no_gps_available), Toast.LENGTH_LONG).show();
|
Toast.makeText(this, getString(R.string.off_router_service_no_gps_available), Toast.LENGTH_LONG).show();
|
||||||
|
@ -220,33 +218,4 @@ public class NavigationService extends Service implements LocationListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class OnNavigationServiceAlarmReceiver extends BroadcastReceiver {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
final WakeLock lock = getLock(context);
|
|
||||||
final NavigationService service = ((OsmandApplication) context.getApplicationContext()).getNavigationService();
|
|
||||||
// do not do nothing
|
|
||||||
if (lock.isHeld() || service == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
lock.acquire();
|
|
||||||
// request location updates
|
|
||||||
final LocationManager locationManager = (LocationManager) service.getSystemService(Context.LOCATION_SERVICE);
|
|
||||||
locationManager.requestLocationUpdates(service.getServiceOffProvider(), 0, 0, service);
|
|
||||||
if (service.getServiceOffInterval() > service.getServiceError()) {
|
|
||||||
service.getHandler().postDelayed(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// if lock is not anymore held
|
|
||||||
if (lock.isHeld()) {
|
|
||||||
lock.release();
|
|
||||||
locationManager.removeUpdates(service);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, service.getServiceError());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package net.osmand.plus;
|
||||||
|
|
||||||
|
import net.osmand.plus.activities.OsmandApplication;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.location.LocationManager;
|
||||||
|
import android.os.PowerManager.WakeLock;
|
||||||
|
|
||||||
|
public class OnNavigationServiceAlarmReceiver extends BroadcastReceiver {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
final WakeLock lock = NavigationService.getLock(context);
|
||||||
|
final NavigationService service = ((OsmandApplication) context.getApplicationContext()).getNavigationService();
|
||||||
|
// do not do nothing
|
||||||
|
if (lock.isHeld() || service == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
lock.acquire();
|
||||||
|
// request location updates
|
||||||
|
final LocationManager locationManager = (LocationManager) service.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
locationManager.requestLocationUpdates(service.getServiceOffProvider(), 0, 0, service);
|
||||||
|
if (service.getServiceOffInterval() > service.getServiceError()) {
|
||||||
|
service.getHandler().postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// if lock is not anymore held
|
||||||
|
if (lock.isHeld()) {
|
||||||
|
lock.release();
|
||||||
|
locationManager.removeUpdates(service);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, service.getServiceError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -693,7 +693,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
||||||
if(settings.AUTO_ZOOM_MAP.get() && location.hasSpeed()){
|
if(settings.AUTO_ZOOM_MAP.get() && location.hasSpeed()){
|
||||||
int z = defineZoomFromSpeed(location.getSpeed(), mapView.getZoom());
|
int z = defineZoomFromSpeed(location.getSpeed(), mapView.getZoom());
|
||||||
if(mapView.getZoom() != z && !mapView.mapIsAnimating()){
|
if(mapView.getZoom() != z && !mapView.mapIsAnimating()){
|
||||||
long now = SystemClock.elapsedRealtime();
|
long now = System.currentTimeMillis();
|
||||||
// prevent ui hysterisis (check time interval for autozoom)
|
// prevent ui hysterisis (check time interval for autozoom)
|
||||||
if(Math.abs(mapView.getZoom() - z) > 1 || (lastTimeAutoZooming - now) > 6500){
|
if(Math.abs(mapView.getZoom() - z) > 1 || (lastTimeAutoZooming - now) > 6500){
|
||||||
lastTimeAutoZooming = now;
|
lastTimeAutoZooming = now;
|
||||||
|
|
Loading…
Reference in a new issue