Open DaneHoward opened 1 year ago
I face the same issue.
Capture video is work, but the resultCode
is RESULT_CANCELED
(in onActivityResult
). If I ignore the resultCode
, the later steps all execute correctly (I can get the video, do the upload, etc.).
It's strange...
I found that the reason why it causes the result to be "Error: User cancelled xx" is because the confirmation screen (see the screenshot below) is missing after clicking end recording.
I use a local android project (without react-native, pure native) and test the "same" code to come out with this screen, so there is no problem.
I tried adjusting the react-native version, the android os version and android sdk version and found that only react-native + android 13 devices have this problem (regardless of react-native version and android sdk version).
But I still don't know how to fix this issue ....
I encountered the same error when trying to do video capture on an Android emulator that was using Android 13, but when I created a test build and put it on a real device both the image and video capturing worked correctly.
Currently using version 0.37.3 of react-native-image-crop-picker and version 0.68.5 of RN.
I am stuck at this. Any progress here.
@huanguolin @jde8aa @Talhafayyaz11 Hi friends! I will mark this issue as resolved but first, let me help ya out!
So, I'm going to take a stab that all 3 of you are using Android 13+ which is giving the "didCancel" response.
This is not an issue with the image picker (well, the docs could be clearer)
This is a PERMISSION ISSUE!
The fix should look like this:
import { PermissionsAndroid, Platform, } from 'react-native';
Then in your component:
try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.CAMERA, { title: "Cool Photo App Camera Permission", message: "Cool Photo App needs access to your camera " + "so you can take awesome pictures.", buttonNeutral: "Ask Me Later", buttonNegative: "Cancel", buttonPositive: "OK" } ); if (granted === PermissionsAndroid.RESULTS.GRANTED) { return true; } else { return false; } } catch (err) { console.warn(err); return false; }
This should fix up any Android 13 Video capture issues related to didCancel. Since at least the 4 of us have had this issue (and I assume more) They should make more of a stink about it in the docs but the code works.
++ wrap a little magic around this using Platform.OS to account for iOS and you're back in business!
Thanks for the suggestion @DaneHoward but permissions have already been obtained in my case. The video capture simply doesn't work on Android emulators running Android 13 for me. It works fine on a real device though, and image capturing works fine on both emulators and real devices.
same here doesn't work in android 13 emulator
08-28 19:25:53.050 10120 10120 D AndroidRuntime: Shutting down VM
08-28 19:25:53.051 10120 10120 E AndroidRuntime: FATAL EXCEPTION: main
08-28 19:25:53.051 10120 10120 E AndroidRuntime: Process: com.android.camera2, PID: 10120
08-28 19:25:53.051 10120 10120 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.content.ContentValues.put(java.lang.String, java.lang.Long)' on a null object reference
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at com.android.camera.VideoModule.saveVideo(VideoModule.java:1263)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at com.android.camera.VideoModule.stopVideoRecording(VideoModule.java:1513)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at com.android.camera.VideoModule.onStopVideoRecording(VideoModule.java:656)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at com.android.camera.VideoModule.onShutterButtonClick(VideoModule.java:697)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at com.android.camera.ShutterButton.performClick(ShutterButton.java:190)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at android.view.View.performClickInternal(View.java:7483)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at android.view.View$PerformClick.run(View.java:29334)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:942)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:201)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at android.os.Looper.loop(Looper.java:288)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7872)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
08-28 19:25:53.051 10120 10120 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
08-28 19:25:53.054 703 10694 I DropBoxManagerService: add tag=system_app_crash isTagEnabled=true flags=0x2
08-28 19:25:53.055 703 1208 W ActivityTaskManager: Force finishing activity com.android.camera2/com.android.camera.VideoCamera
Version
Tell us which versions you are using:
Platform
Expected behaviour
Videos are captured successfully on openCamera with mediaType option 'video'
Actual behaviour
When capturing a video on Android SDK 33 / Android 13 -> The only response is that the user cancelled even if that's not the case
Steps to reproduce
Init project
Install react-native-image-crop-picker
Try to capture video on an Android 13 (SDK 33) device
Only response on RN side is "Error: User cancelled image selection"
Response in Android emulator is attached below
Additional Info
I wanted to add this section because I've already done some research and hope that helps
Attachments
// stacktrace or any other useful debug info I get this bad boy in the Android Emulator:
Love react-native-image-crop-picker? Please consider supporting our collective: 👉 https://opencollective.com/react-native-image-crop-picker/donate