Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Request always permission on Android #281

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/geolocation.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,21 @@ function _getLocationRequest(options: Options): any {
return mLocationRequest;
}

function _requestLocationPermissions(): Promise<any> {
function _requestLocationPermissions(always: boolean): Promise<any> {
return new Promise<any>(function (resolve, reject) {
if (LocationManager.shouldSkipChecks()) {
resolve();
} else {
permissions.requestPermission((<any>android).Manifest.permission.ACCESS_FINE_LOCATION).then(resolve, reject);
if (always) {
permissions.requestPermission((<any>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((<any>android).Manifest.permission.ACCESS_FINE_LOCATION).then(resolve, reject);
}

}
});
}
Expand Down Expand Up @@ -202,7 +211,7 @@ export function clearWatch(watchId: number): void {

export function enableLocationRequest(always?: boolean): Promise<void> {
return new Promise<void>(function (resolve, reject) {
_requestLocationPermissions().then(() => {
_requestLocationPermissions(always).then(() => {
_makeGooglePlayServicesAvailable().then(() => {
_isLocationServiceEnabled().then(() => {
resolve();
Expand Down