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();