0

Hi i'm trying to request location permission, i added some custom message but app not showing custom message, it is always showing default message

``` const requestLocationPermission = async () => {
try {
const granted = await request(
  Platform.select({
    android: PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION,
    ios: PERMISSIONS.IOS.LOCATION_WHEN_IN_USE,
  }),
  {
    title: 'MyApp',
    message:
      'MyApp collects location data to enable mapping, job routing, and direction services even when the app is closed or not in use.',
    buttonNeutral: 'Ask Me Later',
    buttonNegative: 'Cancel',
    buttonPositive: 'OK',
  },
);
console.log('granted', granted);
if (granted === 'granted') {
  console.log('You can use Geolocation');
  return true;
} else {
  console.log('You cannot use Geolocation');
  return false;
}
} catch (err) {
return false;
}
} ; ```
Joshi G
  • 453
  • 9
  • 16

1 Answers1

0

When requestion a permission from the user there are two dialogues on Android. The first one is called a rationale (explained here) and is optional. It explains to the user why this permission is being requested. If the user accepts then the second dialogue will be shown. No permission has been granted yet.

The second dialogue is a system dialogue. Messages cannot be changed so the dialogue will always look exactly the same.

In your case it seems the rationale is skipped even though you have provided one to the request method. From the documentation it says:

If rationale is provided, this function checks with the OS whether it is necessary to show a dialog explaining why the permission is needed (https://developer.android.com/training/permissions/requesting.html#explain) and then shows the system permission dialog.

As you can see before react shows the rationale it asks Android whether it's necessary to show it. I suppose it calls shouldShowRequestPermissionRationale. And because this call returns false your message will not be shown.

So the behaviour you get is absolutely normal.

zomega
  • 1,538
  • 8
  • 26