react-native-image-picker: Couldn't get file path for photo

  • Please read the following carefully before opening a new issue. Your issue may be closed if it does not provide the information required by this template.

Environment: OS: macOS Sierra 10.12.6 Node: 9.1.0 Yarn: 1.3.2 npm: 6.1.0 Watchman: 4.9.0 Xcode: Xcode 9.2 Build version 9C40b Android Studio: 3.1 AI-173.4720617

Packages: (wanted => installed) react: ^16.4.1 => 16.4.1 react-native: ^0.55.4 => 0.55.4

“react-native-image-picker”: “^0.26.10”

when i took the photo ,it crash: Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/28756 from pid=1655, uid=10152 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()

when i Taking pictures: ImagePicker Error: Couldn’t get file path for photo

my permission: <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

I set up, <provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data tools:replace="android:resource" android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_image_picker_paths" /> </provider>

but No role。

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 22

Most upvoted comments

I was able to fix it by adding android:requestLegacyExternalStorage="true" to application tag in AndroidManifest.xml file

@wcandillon @edilsonlm217 @PragyanD33p @ZenBoat

I also faced this issue that happened if you select the first time take photo not choose from library so I think related to storage android permissions. according to android permission i made

const checkAllPermissions = async () => {
        try {
            await PermissionsAndroid.requestMultiple
            ([PermissionsAndroid.PERMISSIONS.CAMERA, PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE, PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE]);
            if ((await PermissionsAndroid.check('android.permission.CAMERA')) &&
                (await PermissionsAndroid.check('android.permission.CAMERA')) &&
                (await PermissionsAndroid.check('android.permission.CAMERA'))) {
                console.log('You can use the camera');
                return true;
            } else {
                console.log('all permissions denied');
                return false;
            }
        } catch (err) {
            console.warn(err);
        }
    };

and call this function before use ImagePicker. and works well now from the first time select take Photo.

FilePath.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="app_images" path="."/>
</paths>

i hope your problem will be resolve

it not working with android 10

Environment: “react-native”: “0.61.5”,