Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Android Permission Denied

Tags:

react-native

I am testing an app on Android 5.1.1 where the storage permission gets denied automatically. When I launch the app there is no prompt for giving permissions to the app. However, when I test the app on Android 6.0 and above with new android permissions model everything is working fine. How do I set the permissions correctly and get the permissions dialog box to prompt on app launch on android 5.0 and below?

like image 242
Aritra Dattagupta Avatar asked Jun 25 '26 22:06

Aritra Dattagupta


1 Answers

I just hit this same issue on the location permission for android version 5.0.

This appears to be a bug in RN (we're using v0.44.0)

  const granted = await PermissionsAndroid.request(
    PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, {
      title: 'Enable Location Tracking',
      message: 'Use your location to find nearby things',
    },
  );

  if (granted === PermissionsAndroid.RESULTS.GRANTED) {
    return true;
  }

For some reason, on android 5.0, granted gets set to true, instead of "granted", which is what it gets set to on 6.0+.

I worked around it by changing

  if (granted === true || granted === PermissionsAndroid.RESULTS.GRANTED)
like image 98
Philberg Avatar answered Jun 27 '26 11:06

Philberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!