skip to Main Content

I use react-native-permissions to get the camera permission and it work well in iOS.
But I can’t get callback of android permission when user agrees or rejects.
I tried replacing it with PermissionsAndroid but I had the same issue.

Finally, I created a new project of React Native and using the same code I was able to get callback of android permission. What is the reason for this situation?

Note: Both projects use the same version of React Native.

2

Answers


  1. Chosen as BEST ANSWER

    I found that my problem came from the use of the onRequestPermissionsResult method in the original Android project, as long as I annotate it everything works fine.

    I tried to understand the reason and found out that the previous maintenance project person did not write super in onRequestPermissionsResult, which caused react native to not call back the result after obtaining the permission.


    1. Make sure you have this in your android/app/src/main/AndroidManifest.xml file. If not, then add it and rebuild your app.
    <uses-permission android:name="android.permission.CAMERA" />
    
    1. You can check the status of your permission request and see if it’s blocked or granted.
    import RNPermissions, { PERMISSIONS } from 'react-native-permissions';
    
    const requestCameraPermission = async () => {
      const p = PERMISSIONS.ANDROID.CAMERA;
      const checkStatus = await RNPermissions.check(p);
      console.log('checkStatus', checkStatus);
      const requestStatus = await RNPermissions.request(p);
      console.log('requestStatus', requestStatus);
    };
    
    1. It’s possible that you might have denied permission the first time, in which case the response to further request() will always be blocked. In such case you should go app settings and change the permission manually.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search