From a682f13b2e5c2e82a05919029a0d511e1f1fe172 Mon Sep 17 00:00:00 2001 From: Eduard Date: Mon, 21 Jun 2021 11:22:19 +0200 Subject: [PATCH] Use the optional always parameter also for the Android location request in order to determine if ACCESS_BACKGROUND_LOCATION should be requested --- src/geolocation.android.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/geolocation.android.ts b/src/geolocation.android.ts index e003613..e710e4d 100644 --- a/src/geolocation.android.ts +++ b/src/geolocation.android.ts @@ -124,12 +124,21 @@ function _getLocationRequest(options: Options): any { return mLocationRequest; } -function _requestLocationPermissions(): Promise { +function _requestLocationPermissions(always: boolean): Promise { return new Promise(function (resolve, reject) { if (LocationManager.shouldSkipChecks()) { resolve(); } else { - permissions.requestPermission((android).Manifest.permission.ACCESS_FINE_LOCATION).then(resolve, reject); + if (always) { + permissions.requestPermission((android).Manifest.permission.ACCESS_BACKGROUND_LOCATION) + .then(resolve, reject) + .catch((e) => { + console.error("Failed to request Android background location permission due to: " + e); + }); + } else { + permissions.requestPermission((android).Manifest.permission.ACCESS_FINE_LOCATION).then(resolve, reject); + } + } }); } @@ -202,7 +211,7 @@ export function clearWatch(watchId: number): void { export function enableLocationRequest(always?: boolean): Promise { return new Promise(function (resolve, reject) { - _requestLocationPermissions().then(() => { + _requestLocationPermissions(always).then(() => { _makeGooglePlayServicesAvailable().then(() => { _isLocationServiceEnabled().then(() => { resolve();