react-native-image-crop-picker
react-native-image-crop-picker copied to clipboard
openPicker() wont return response after selecting image in Android
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
-
Press the button that calls the function that opens the gallery with openPicker()
-
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) }); }
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 if you are facing this only for Android 10 you can add following 2 lines in your AndroidManifest.xml
...
android:requestLegacyExternalStorage="true"
....
@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 :(
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"
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.