0

have anyone make the library react-native-image-picker work on Android below version 5?. In my case when i call to showImagePicker it always goes to didCancel.

const options = {
            quality: 0.7,
            maxWidth: 500,
            maxHeight: 500,
            storageOptions: {
                skipBackup: true
            },
        };

        ImagePicker.showImagePicker(options, (response) => {

            if (response.didCancel) {
                console.log('User cancelled photo picker');
            }
            else if (response.error) {
                console.log('ImagePicker Error: ', response.error);
            }
            else if (response.customButton) {
                console.log('User tapped custom button: ', response.customButton);
            }
            else {
                var image = 'data:image/jpeg;base64,' + response.data
            }
        });

When i press Choose from Library or Take Picture it shows the Gallery or Camera but right away the completion function gets called with response.didCancel = true, is not waiting for the user to select so the completion could have the image.

Any thoughts?

Gabriel Candia
  • 282
  • 4
  • 14

1 Answers1

2

After debugging the Android part of the problem i got that the onActivityResult() was called prematurely. After reading a little bit in this post:

onActivityResult() called prematurely

Changing in the AndroidManifest the activity launchMode from singleInstance to singleTop fix the issue.

<activity
    android:name=".MainActivity"
    android:launchMode="singleTop"
...

Hope it helps if someone is struggling with something similar.

Gabriel Candia
  • 282
  • 4
  • 14