[expo-location] request permission always returns denied
See original GitHub issueSummary
If the user initially deny location permission, but consequently grant permission from settings, the location always still returns as “denied”. This problem is very similar to #15273 in expo-media-library
Steps to reproduce:
- Clear app state so app will ask to allow location permissions
- Deny location permissions
- Allow location permission from the settings
- Reopen the app => permissions is still denied
Settings | App |
---|---|
![]() |
![]() |
Managed or bare workflow? If you have ios/
or android/
directories in your project, the answer is bare!
managed
What platform(s) does this occur on?
Android
SDK Version (managed workflow only)
44.0.0
Environment
expo-env-info 1.0.2 environment info: System: OS: macOS 12.2.1 Shell: 5.8 - /bin/zsh Binaries: Node: 12.22.1 - ~/.nvm/versions/node/v12.22.1/bin/node Yarn: 1.22.17 - ~/.nvm/versions/node/v12.22.1/bin/yarn npm: 7.24.1 - ~/.nvm/versions/node/v12.22.1/bin/npm Watchman: 2022.03.14.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5 IDEs: Android Studio: 2021.1 AI-211.7628.21.2111.8139111 Xcode: 13.3/13E113 - /usr/bin/xcodebuild npmPackages: expo: ^44.0.0 => 44.0.6 react: 17.0.1 => 17.0.1 react-dom: 17.0.1 => 17.0.1 react-native: 0.64.3 => 0.64.3 react-native-web: 0.17.1 => 0.17.1 react-navigation: ^4.4.4 => 4.4.4 Expo Workflow: managed
Reproducible demo
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:11 (3 by maintainers)
Hi people! There are a couple of things going on here. It’s going to be a long explanation, but I hope it clears up things for a lot of people 😄
Android option “Allow all the time” is a background permission Android tries to differentiate the two location access types with fore- and background categories (Android docs). This is important to keep in mind when requesting location permissions on Android.
From Android 11, you need foreground permission before asking background permission This is quite unfortunate but Android now enforces its “best practice” of requesting permissions. If you need access to the background location, you first have to ask for foreground permissions. Without these foreground permissions, the app is blocked from the background location even though users granted them through the app settings. From their docs:
expo-location
only registers new permissions on cold start, or throughrequestForegroundPermissionAsync
/requestBackgroundPermissionAsync
In the code example, you use thereact-use
useAsync
hook, which is great in most cases. Unfortunately, you never start the permission request through the proper methods. When the linking page is opened, the app is put in background state. When the linking page is closed, the app is put back in foreground state without any refresh or update to it.requestXPermissionAsync
call to set the scoped permissions properly.As @borasumer correctly noted, we do have permission hooks that can help you overcome most of these issues (including updating permission status whenever the user switches back from the app settings page). But, you still have to keep in mind that permissions needs to be requested through the
requestXPermissionAsync
methods, and Android wants a granted foreground permission first.This code snippet should handle pretty much all edge cases for requesting these permissions
Hope this helps!
Finding the same issue with expo-camera
Camera.requestCameraPermissionsAsync()