Fix location permission crash (NavigationService)
This commit is contained in:
parent
f693f766c9
commit
1e05e51d72
1 changed files with 13 additions and 2 deletions
|
@ -144,6 +144,9 @@ public class NavigationService extends Service implements LocationListener {
|
|||
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||
try {
|
||||
locationManager.requestLocationUpdates(serviceOffProvider, 0, 0, NavigationService.this);
|
||||
} catch (SecurityException e) {
|
||||
Toast.makeText(this, R.string.no_location_permission, Toast.LENGTH_LONG).show();
|
||||
Log.d(PlatformUtil.TAG, "Location service permission not granted"); //$NON-NLS-1$
|
||||
} catch (IllegalArgumentException e) {
|
||||
Toast.makeText(this, R.string.gps_not_available, Toast.LENGTH_LONG).show();
|
||||
Log.d(PlatformUtil.TAG, "GPS location provider not available"); //$NON-NLS-1$
|
||||
|
@ -202,7 +205,11 @@ public class NavigationService extends Service implements LocationListener {
|
|||
usedBy = 0;
|
||||
// remove updates
|
||||
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||
try {
|
||||
locationManager.removeUpdates(this);
|
||||
} catch (SecurityException e) {
|
||||
Log.d(PlatformUtil.TAG, "Location service permission not granted"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
if (!isContinuous()) {
|
||||
WakeLock lock = getLock(this);
|
||||
|
@ -225,7 +232,11 @@ public class NavigationService extends Service implements LocationListener {
|
|||
if (!isContinuous()) {
|
||||
// unregister listener and wait next time
|
||||
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||
try {
|
||||
locationManager.removeUpdates(this);
|
||||
} catch (SecurityException e) {
|
||||
Log.d(PlatformUtil.TAG, "Location service permission not granted"); //$NON-NLS-1$
|
||||
}
|
||||
WakeLock lock = getLock(this);
|
||||
if (lock.isHeld()) {
|
||||
lock.release();
|
||||
|
|
Loading…
Reference in a new issue