react-native-image-crop-picker icon indicating copy to clipboard operation
react-native-image-crop-picker copied to clipboard

openPicker() wont return response after selecting image in Android

Open roberto210394 opened this issue 2 years ago • 5 comments

Version

Tell us which versions you are using:

  • react-native-image-crop-picker v0.35.3
  • react-native v0.64.2

Platform

Tell us to which platform this issue is related

  • Android

Expected behaviour

After picking an image from the gallery when using openPicker() it is expected to return a response in the 'then' block of code

Actual behaviour

When picking an image the gallery just closes and never enter the 'then' block of code. It doesn't show any type or error

Steps to reproduce

  1. Press the button that calls the function that opens the gallery with openPicker()

  2. Select an image from the gallery, the gallery will close but it will not return a response

Attachments

I'm using flipper for debug but it doesn't show any error message or whatsoever. It works fine on ios

Here is my code

const ImagePickerProps = { width: 300, height: 300, cropping: true, compressImageMaxWidth: 300, compressImageMaxHeight: 300, cropperCancelText: 'Cancelar', cropperChooseText: 'Elegir', cropperToolbarTitle: 'Editar foto', includeBase64: true, compressImageQuality: 0.6, };

onPressGaleria = () => { ImagePicker.openPicker(ImagePickerProps) .then(img => { // it doesn't reach this part of the code this.onSuccesChangeAvatar(img) }); }

roberto210394 avatar May 10 '22 20:05 roberto210394

I have tried this

ImagePicker.openPicker(ImagePickerProps) .then(img => { // it doesn't reach this part of the code this.onSuccesChangeAvatar(img) }) .catch(error => { console.log(error) }) .finally( console.log('it only reach this part of the code') );

As it says, it only reach the finally

roberto210394 avatar May 10 '22 20:05 roberto210394

@roberto210394 if you are facing this only for Android 10 you can add following 2 lines in your AndroidManifest.xml <application
... android:requestLegacyExternalStorage="true" ....

amithardikar avatar May 17 '22 06:05 amithardikar

@roberto210394 if you are facing this only for Android 10 you can add following 2 lines in your AndroidManifest.xml <application ... android:requestLegacyExternalStorage="true" ....

I've already tried that but it doesn't seem to work, i've tried using android 8.1, 10 and 11 :(

roberto210394 avatar May 17 '22 14:05 roberto210394

I have a same problem I also do a try catch that I got message from openPicker method "Error: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getScheme()' on a null object reference"

TheKuyPeD avatar May 26 '22 05:05 TheKuyPeD

If you're using ReactInstanceManager in an activity where you're implementing a ReactRootView then make sure to override onActivityResult as this is what passes the image data from the native image picker back to the react view:

Kotlin Code:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    reactInstanceManager.onActivityResult(this, requestCode, resultCode, data)
    super.onActivityResult(requestCode, resultCode, data)
}

This is most likely the case if you're implementing React Native components into an existing Android app.

BeemWex avatar Sep 21 '22 16:09 BeemWex