react-native-image-picker: Couldn't get file path for photo on ANDROID 10 EMU
Bug
Camera doesn’t open after granting permission and selecting Take Photo from popup.
Previously I was using version 1.1.0 on Android 9 without issue. After upgrading to Android 10 I started getting this error. Issue 1269 is confirming the latest build v2.3.1 fixes this issue but after upgrading to 2.3.1 I am still getting the same error. This is on an Android 10 emulator.
react-native info output:
System: OS: Windows 10 10.0.17134 CPU: (12) x64 Intel® Core™ i7-8850H CPU @ 2.60GHz Memory: 2.49 GB / 15.80 GB Binaries: Node: 10.16.3 - C:\Program Files\nodejs\node.EXE Yarn: 1.17.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD npmPackages: react: 16.9.0 => 16.9.0 react-native: 0.61.5 => 0.61.
Library version: ^2.3.1
Buildscript:
ext {
buildToolsVersion = "29.0.2"
minSdkVersion = 16
supportLibVersion = "29.0.0"
compileSdkVersion = 29
targetSdkVersion = 29
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Usage:
ImagePicker.showImagePicker(options, async (response) => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
console.log(response);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.uri };
}
});
}
//ImagePicker Error: Couldn't get file path for photo
The workaround in 1269 asking for permission did not work either. I still log the same error.
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{
title: 'We need your permission'
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('You can use the camera');
ImagePicker.showImagePicker(options, async (response) => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
console.log(response);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.uri };
}
});
}
else {
console.log('Camera permission denied');
}
Did I miss a step here?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 29 (1 by maintainers)
Commits related to this issue
- Support scoped storage (Camera and images only) See also * https://github.com/react-native-community/react-native-image-picker/issues/1269 * https://github.com/react-native-community/react-native-ima... — committed to lotusshinoaki/react-native-image-picker by lotusshinoaki 4 years ago
- Support scoped storage (Camera and images only) See also * https://github.com/react-native-community/react-native-image-picker/issues/1269 * https://github.com/react-native-community/react-native-ima... — committed to lotusshinoaki/react-native-image-picker by lotusshinoaki 4 years ago
I was able to apply a short term fix to get this going by adding
android:requestLegacyExternalStorage="true"to application tag in AndroidManifest.xml file.I believe this is due to Android 10 scoped storage privacy changes and will require updating the library and how it reads/writes from the filesystem. My android dev experience is very limited but will submit a PR if I am able to figure it out.
Having the same issue in Android 10/ API 29…
Having the same issue in Android 10!
A possible workaround (if you don’t need your pics to be public) is to use the
privateDirectoryflag:This didn’t work for me
Not Working!!!
any news for this issue ?
We also have this issue on Android 10! The
requestLegacyExternalStoragefix does solve the problem, but definitely is just a temporary fix, but with Android 11 beta coming out this month, we probably need a more definite fix!Has anyone started investigating what the fix would entail or started on it!
Just did a PR with the fixes, for the moment you can add in your package.json the following:
Google Play Store now requires to target API 29 as you can see here https://developer.android.com/distribute/best-practices/develop/target-sdk
Having the same issue in Android 10!
Hello Guys, I think this is not for everyone, but in my build.gradle file it was configured to use API 29.0.2 I just switched to API 28.0.3 - Sure with the SDK and NDK properly installed and working … After that I ran the Build and it worked fine on my android 10 device
Check if there are other modules in your project that use the same provider. If so, please change this module AndroidManifest.xml :
<provider android:name="com.imagepicker.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" /> </provider>to<provider android:name="com.imagepicker.FileProvider" android:authorities="${applicationId}.PickProvider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/pick_provider_paths" /> </provider>RealPathUtil.java:
providertoPickProvider@mhashim6 There was a problem with fixing https://github.com/lotusshinoaki/react-native-image-picker/commit/760299874f2a3075573f66ad251ab273e283fbd1 Unable to get metadata (such as MediaStore.MediaColumns.WIDTH) from URL using ContentResolver. So I don’t think this is generally a good (and well worth creating PR) solution.
requestLegacyExternalStoragewill be ignored as soon as you choose targetSdk 30. See: https://developer.android.com/preview/privacy/storageSo as @paulmasters asked, we need a long term fix for this.