react-native-image-picker: Android 10: Camera Doesn't Open After Granting Permission
Bug report
Summary
When using ImagePicker.showImagePicker, after granting permission for camera use selecting “Take a photo” does not open the camera.
On an Android 10 device (I used a Pixel 2 XL)
-
Find a place in the code to kick off
ImagePicker.showImagePicker(), a button might be easiest -
When the image picker kicks off, allow permissions for both camera and device storage
-
Ensure that the camera does not launch, even though it should
Environment info
react-native info output:
System:
OS: macOS 10.15.3
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Memory: 166.34 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.4 - ~/.nvm/versions/node/v10.16.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.3 - /Users/dustinmcrorie/.rvm/rubies/ruby-2.5.7/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Xcode: 11.5/11E608c - /usr/bin/xcodebuild
Languages:
Java: 14.0.1 - /usr/bin/javac
Python: 2.7.17 - /usr/local/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: 0.62.0 => 0.62.0
npmGlobalPackages:
*react-native*: Not Found
Library version: 2.3.3
Steps to reproduce
- Use an Android 10 device, a Pixel 2 XL would be ideal if available
- Find a place in the code to kick off
ImagePicker.showImagePicker(), a button might be easiest - When the image picker kicks off, allow permissions for both camera and device storage
- Choose the “take a photo” option
Describe what you expected to happen:
- The camera should launch, but the camera does not launch (the bug 🐛 ), saying “Could not get filepath”
Reproducible sample code
ImagePicker.showImagePicker({}, (response) => {
uploadFileFromResponse(response);
});
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 44
- Comments: 36 (2 by maintainers)
Please stop spamming the issue with
+1comments. If you are experiencing the same problem, and don’t have anything valuable to add, use reaction instead.Spamming the issue only makes it difficult to find valuable comments which could actually help with fixing the issue.
As of now, there are 2 workarounds before a proper fix is provided:
requestLegacyExternalStorageflag as mentioned here: https://github.com/react-native-community/react-native-image-picker/issues/1233#issuecomment-561349254lower your targetSDK to version 28 (
android/build.gradle):The issue can be related to new package visibility (https://developer.android.com/about/versions/11/privacy/package-visibility). After all updates (at least Android Studio 4.1) try to add in your manifest
<queries>that shows what action is required in app. In my case problem disappears when adds.IMAGE_CAPTURE -> CAMERA, GET_CONTENT -> GALLERY (to get files change mimeType if you want video) PICK -> GALLERY (should change mimetype if u want video) CHOOSER -> GALLERY (if someone have other image browsers)
You can also check in logcat what queries you have to add (should contains “BLOCKED” or “no permission”. Error is because ImagePickerModule when you don’t have permission in Intent with resolveActivity returns null (u can comment it to check better errors in startActivityForResult)
I hope that can help you
Hey, same for me with RN 0.63.2 and 2.3.3. Camera did not open and Logical say’s “Permission denied”.
With this option android:requestLegacyExternalStorage=“true” it works at the moment.
+1 A fix for this prior to Android 11 coming out of beta would be great.
Maybe it’s worth to the Readme file?
+11111111111111111111111111
I used this solution it worked on development, when deployed to internal test on google play and install from the store it didn’t work
@NMahendroo This solution will be deprecated as of Android 11 (this line in the manifest will be ignored), so a more permanent solution will still need to be found.
+1
+1
But lowering the target sdk version is not a solution given that Google Play will reject app:
https://developer.android.com/distribute/best-practices/develop/target-sdk
This thread is too old with solution for various versions of this library. The latest version does not have this issue, feel free to create a new issue with details. I am happy to fix it. Thanks.
+1
+1 a fix for this
works now with - android:requestLegacyExternalStorage=“true” against SDK 29 targetSdkVersion = 29 compileSdkVersion 29 buildToolsVersion = “29.0.3”
I receive a notification from google and new apps will not accept target version less than 29 and how don’t use it yet will need to upgrade.
A possible workaround (if you don’t need your pics to be public) is to use the
privateDirectoryflag:@AllanKlaus I installed the app to the Google Play Internal App Sharing too but was able to get the Camera and Photos to open with this setting. However, I was not able to upload the actual image. Not sure if this issue is directly related with Image Picker or the latest version of React Native (0.63.2).