16

Steps to replicate:

react-native init project

<add code below to the project(App.js component)>

react-native run-android

I called the function in onPress of a text component.

The permission request always returns never_ask_again even for the fresh app run.

async requestPermissions() {
// android 6.0 +
if (Platform.OS === 'android' && Platform.Version >= 23) {
  try {
    const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, {
      'title': 'Let the access location',
      'message': 'locate you.'
    });
    console.log('granted: ', granted);
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      Alert.alert("Granted access", [{ text: "ok" }])
    } else {
      Alert.alert(
        "can't access to GPS title",
        "returned " + granted,
        [
          { text: "ok" }
        ]
      );
    }
  } catch (err) {
  }
}
}

Even when the permissions is enabled from settings, still the never_ask_again is returned.

React Native Version: 0.55.2

React Version: 16.3.1

in app/build.gradle

targetSdkVersion 23

Thanks

snjmhj
  • 1,001
  • 11
  • 21
  • Did you ever find out what the problem was? Additionally for me, `PermissionsAndroid.check` always return `false` even when the permission has been granted. – laurent May 21 '18 at 16:12
  • 2
    One thing I missed was to add `` in `AppManifest.xml` @this.lau_ – snjmhj May 22 '18 at 04:25
  • 1
    @snjmhj Use react-native-permissions https://github.com/yonahforst/react-native-permissions – Vvk Jun 19 '18 at 04:25
  • @snjmhj thank you It worked. I think you should write it in the answer instead of writing it in comment – Yash Pokar Apr 23 '20 at 13:54

2 Answers2

13

One thing I missed was to add <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> in AppManifest.xml

Edison Biba
  • 4,384
  • 3
  • 17
  • 33
snjmhj
  • 1,001
  • 11
  • 21
1

You will have to add <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> in AndroidManifest.xml not AppManifest.xml

SJM
  • 81
  • 3