Search code examples
react-nativereact-native-permissions

Checking Previously Granted Permissions in React Native using PermissionsAndroid API


Is there a way to check if a list of permissions have already been granted in React Native using the PermissionsAndroid API, similar to how PermissionsAndroid.requestMultiple() can be used to request multiple permissions? I'm looking for a method like PermissionsAndroid.checkMultiple() to allow me to check if a list of permissions were already granted.

I would appreciate some suggestions on this.


Solution

  • The simple wrapper would be something like this (not the same thing, but solves the problem):

    const checkPermissions = (permissions: Permission[]): Promise<boolean[]> => {
      return Promise.all(permissions.map((p) => PermissionsAndroid.check(p)))
    }
    
    let granted = await checkPermissions([
      PermissionsAndroid.PERMISSIONS.CAMERA,
      PermissionsAndroid.PERMISSIONS.RECORD_AUDIO
    ])
    console.log(granted) // [false,false]