"User cancelled image selection" error when call openPicker
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch [email protected] for the project I'm working on.
It solved a problem that throw "User cancelled image selection" error when call openPicker method on Vivo devices
Here is the diff that solved my problem:
diff --git a/node_modules/react-native-image-crop-picker/android/src/main/java/com/reactnative/ivpusic/imagepicker/PickerModule.java b/node_modules/react-native-image-crop-picker/android/src/main/java/com/reactnative/ivpusic/imagepicker/PickerModule.java
index c6b09a9..33bab98 100644
--- a/node_modules/react-native-image-crop-picker/android/src/main/java/com/reactnative/ivpusic/imagepicker/PickerModule.java
+++ b/node_modules/react-native-image-crop-picker/android/src/main/java/com/reactnative/ivpusic/imagepicker/PickerModule.java
@@ -372,8 +372,8 @@ class PickerModule extends ReactContextBaseJavaModule implements ActivityEventLi
galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiple);
galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
- final Intent chooserIntent = Intent.createChooser(galleryIntent, "Pick an image");
- activity.startActivityForResult(chooserIntent, IMAGE_PICKER_REQUEST);
+// final Intent chooserIntent = Intent.createChooser(galleryIntent, "Pick an image");
+ activity.startActivityForResult(galleryIntent, IMAGE_PICKER_REQUEST);
} catch (Exception e) {
resultCollector.notifyProblem(E_FAILED_TO_SHOW_PICKER, e);
}
This issue body was partially generated by patch-package.
Hi, thank you for your help and attempt to solve the issue, @kurisu994.
I did the same and it did not solve the issue.
- I installed patch-package lib with "yarn add patch-package postinstall-postinstall";
- I added the script to package.json:
"scripts": {
+ "postinstall": "patch-package"
}
- I made the fixes you made;
- I created the patch with "yarn patch-package react-native-image-crop-picker" (v0.38.0);
- I applied the patch running "yarn patch-package";
- I ran "yarn android" and it did not solve the problem.
I solved the problem with try/catch:
import ImagePicker from 'react-native-image-crop-picker';
const getImage = async () => {
try {
const image = await ImagePicker.openPicker({
width: 300,
height: 400,
cropping: true
});
const result = { uri: image.path }
return result;
} catch (error) {
console.warn(error);
}
}
export default getImage;
This way, it does not crashes when the user cancel the picker. We just need to ignore the warning.
@Brenosalv greeting!
In my project android/app/src/main/AndroidManifest.xml MainActivity use launchMode="singleTop".
Maybe there's a difference.
这个方案在 0.37.3 版本上可行,在出现问题的 Vivo 手机上测试可以打开相册,其他手机例如小米、魅族、OPPO也是没有问题的。
This solution is feasible on version 0.37.3, and the photo album can be opened by testing on the Vivo mobile phone with problems. Other mobile phones such as Xiaomi, Meizu, and OPPO also have no problems.