skip to Main Content

I have used react-native-image-picker in my project. It is working fine in android phones that are less than Android 11 but App crashes in android 11 without showing logcat. launchImageLibrary is working as expected but launchCamera is crashing app. I have added the permissions also in android manifest file i.e

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

but still no luck.

2

Answers


  1. Chosen as BEST ANSWER

    I fixed it by adding await in launchImageLibrary/launchCamera I have added the code for your reference

    const openCamera = async () => { 
    let options = { quality: 5, maxWidth: 500, maxHeight: 500, includeBase64: true, mediaType: 'photo', noData: true, };
    
    await launchCamera(options, response => { 
    if (response.didCancel) { 
    console.log('Cancelled');
    } else if (response.error) { 
    console.log('Error', response.errorMessage);
    } else { 
    console.log(response); 
    setFilePath(response.uri); 
    setBase64('data:image/png;base64,' + response.base64); } });
    };
    

  2. try to remove

    <uses-permission android:name="android.permission.CAMERA" />
    

    Image-picker don’t need permission

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search