I used the code sample in the documentation and I am supposed to get location permission access prompt and when granted the location services should be automatically enabled on the device to get the current location.
On my Android S6 edge test device I only get the prompt and when I press allow I get a warning that location services are not enabled.
So is there a way to programatically enable location services ?
async askForUserPermissionToGetCurrentLocation() {
// Ask for user’s permission to access location settings
let { status } = await
Expo.Permissions.askAsync(Expo.Permissions.LOCATION);
console.log(status);
// User denied access
if (status !== “granted”) {
console.log(“denied”);
// Otherwise, access granted
} else {
console.log(“permission granted”);
// Get the location
let location = await Expo.Location.getCurrentPositionAsync({});
console.log(location);
this.setState({ location: location });
}
}
Render method is just a text to display the longitude and latitude of the returned location.
Ah right now we have no API for enabling location services programmatically… You could open the settings page URI with the Linking API to have the user enable it from settings.
The code in the expo documentation is working fine, you just have to toggle the location ‘on’ from the drop down bar or from settings, keep in mind that you also have to change method for getting location (“Mode” option in android>8) and change it to “battery saving” or “high accuracy” (By default it is set to “device only”). The default setting will not fetch any location from device. The reason is yet unknown to me but changing it worked in my case. peace
you can do this by following this path (may vary in different android/mobile versions)
settings > security&location > location > mode
you will get three options, choose any except device only.
I think this is only just an issue with expo because our app is in development state. it will be fine once you package the app, though i still have not tested it myself but you can try.
p.s: android will still ask the user permission to allow your app to access location services of the device. i dont think/or know that you can bypass it.