React-native-permissions: Android 10 : asking LocationAlways gives RESULTS.BLOCKED

Created on 16 Apr 2020  路  2Comments  路  Source: zoontek/react-native-permissions

Bug

I try to request/check PERMISSIONS.ANDROID.ACCESS_BACKGROUND_LOCATION but every time I get RESULTS.BLOCKED so I redirect the user to go check the settings of the app, but it's not what I expected. I'd like to have a popup asking for All the time geolocation permission.

Any idea ?

Environment info

System:
    OS: macOS 10.15.3
    CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
    Memory: 187.82 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 13.12.0 - /usr/local/bin/node
    Yarn: 1.22.0 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 23, 26, 27, 28, 29
      Build Tools: 28.0.3
      System Images: android-29 | Google Play Intel x86 Atom
      Android NDK: 19.0.5232133
  IDEs:
    Android Studio: 3.6 AI-192.7142.36.36.6200805
    Xcode: 11.4/11E146 - /usr/bin/xcodebuild
  npmPackages:
    @react-native-community/cli: ^4.5.1 => 4.6.3 
    react: 16.11.0 => 16.11.0 
    react-native: 0.62.0 => 0.62.0 
  npmGlobalPackages:
    react-native-cli: 2.0.1
    react-native-git-upgrade: 0.2.7

Library version: x.x.x

Steps To Reproduce

  1. Try to request always geolocation permission on a recent android device with Android 10 (like Pixel a3)
  2. Ask for PERMISSIONS.ANDROID.ACCESS_BACKGROUND_LOCATION
  3. Get RESULTS.BLOCKED
    ...

Describe what you expected to happen:

  1. Try to request always geolocation permission on a recent android device with Android 10 (like Pixel a3)
  2. Ask for PERMISSIONS.ANDROID.ACCESS_BACKGROUND_LOCATION
  3. Get RESULTS.DENIED or RESULTS.GRANTED

Reproducible sample code

const dummy = async () => {
  try {
    const checkResult = await check(PERMISSIONS.ANDROID.ACCESS_BACKGROUND_LOCATION);
    switch (checkResult) {
      case RESULTS.UNAVAILABLE:
        Alert.alert(i18n.geolocation.notAvailableOnThisDevice);
        return;
      case RESULTS.DENIED:
        // The permission has not been requested / is denied but requestable
       // I ask for it then... (code not shown here)
        break;
      case RESULTS.GRANTED:
        // The permission is granted
        // Then I keep going 
        break;
      case RESULTS.BLOCKED:
        // The permission is denied and not requestable anymore -> App settings
        setTimeout(showGoToSettingsAlert, 1000);
        break;
    }
  } catch (error) {
    console.warn(error);
  }
};

Most helpful comment

@Daavidaviid You have to request both at the same time. This new Android API is quite bad 馃槄

requestMutiple([
  PERMISSIONS.ANDROID.ACCESS_BACKGROUND_LOCATION,
  PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION // or PERMISSIONS.ANDROID.ACCESS_COARSE_LOCATION
])

All 2 comments

@Daavidaviid You have to request both at the same time. This new Android API is quite bad 馃槄

requestMutiple([
  PERMISSIONS.ANDROID.ACCESS_BACKGROUND_LOCATION,
  PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION // or PERMISSIONS.ANDROID.ACCESS_COARSE_LOCATION
])

Thank you. I confirm, it鈥檚 bad

Was this page helpful?
0 / 5 - 0 ratings