skip to Main Content

I am using react-native-image-crop-picker in my react-native application and recording video from the camera in Android It is returning [Error: User cancelled image selection]

react-native-image-crop-picker

Versions used

react-native-image-crop-picker v^0.40.2

react-native v0.72.0

react v18.2.0

Android v13

Platform – Android

Expected behaviour

When we record video using ImagePicker.openCamera recorder video path must be returned as it returns when the image is captured.

Actual behaviour

After the video is recorded and we click ok it gives [Error: User cancelled image selection]

Steps to reproduce

  1. Open Camera.
  2. Record the Video and click OK.
  3. Then we must get the recorded video path but it returns an error [Error: User cancelled image selection].

Sample code

recordVideo = async() => {
  try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.CAMERA,
      {
        title: "App Camera Permission",
        message:"App needs access to your camera ",
        buttonNeutral: "Ask Me Later",
        buttonNegative: "Cancel",
        buttonPositive: "OK"
      }
    );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      ImagePicker.openCamera({
        mediaType:'video'
      })
        .then((image) => {
          console.log(" Image ", image)
        })
        .catch((error) => {
          if (error && error.code === 'E_PICKER_CANCELLED') {
            return false;
          }
        })
    } else {
      console.log("Camera permission denied");
    }
  } catch (err) {
    console.warn(err);
  }
}

2

Answers


  1. Uninstall using npm uninstall react-native-image-crop-picker and again install using npm i react-native-image-crop-picker and don’t forget to add to android/app/src/main/AndroidManifest.xml.

    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/> 
    
    Login or Signup to reply.
  2. Please follow the final step of installation instructions for Android:

    If you use SDK version >= 33, add following to app/src/main/AndroidManifest.xml

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

    [Optional] If you want to use camera picker in your project, add following to app/src/main/AndroidManifest.xml

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

    [Optional] If you want to use front camera, also add following to app/src/main/ AndroidManifest.xml

    <uses-feature android:name="android.hardware.camera" android:required="false" />
    <uses-feature android:name="android.hardware.camera.front" android:required="false" />
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search