1
votes

I'm building a React-Native app with Expo, and I need to check/ask for camera permissions. However it seems like the permissions request will always launch the system permission dialog. How can I check the permission silently, without launching the system dialog?

The code I'm using to check permission is as follows:

const { status } = await Permissions.askAsync(Permissions.CAMERA);
if (status === 'granted') console.log('permission granted!';

I know that the Permissions.askAsync will automatically return if the status===granted, however I'm using a 2-step permission process, where a user first clicks a button to ask for the permission. But if it's already been set earlier, I'd rather not show the button, and just automatically proceed. I've seen some components on NPM that implement this, but I don't think they are compatible with Expo.

1
System dialogs will launch for devices with API level 23 and above. These are the runtime permissions, the system will show this if a permission is required.Shubham Raitka
So there's no way to check the permissions without potentially launching the dialog?GalacticNavigator

1 Answers

2
votes

You should use 'getAsync' instead of 'askAsync': Expo.Permissions.getAsync(type)

const { status } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
if (status !== 'granted') {
   alert('Hey! You might want to enable notifications for my app, they are good.');
}

https://docs.expo.io/versions/latest/sdk/permissions