简体   繁体   中英

Why do FileProvider.getUriForFile cause runtime exception

I follow the Android Developers tutor for taking and saving a picture. The call to FileProvider.getUriForFile in the following code fragment produce runtime error .

Exception -

    Caused by: java.lang.IllegalArgumentException: Failed to find 
configured root that contains /storage/sdcard/Android
/data/com.example.myfirstapp/files/Pictures/JPEG_20161121_150916_-
1008254408.jpg

Java -

if (photoFile != null) {
                Uri photoURI = FileProvider.getUriForFile(this,
                        "com.example.myfirstapp.fileprovider",
                        photoFile);
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
            }

Manifest.xml -

<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.example.myfirstapp.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"></meta-data>
    </provider>

Seems like the problem was in defining the provider within the Manifest file.

Found a solution here ANSWER

Thanks to ImagineThat

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM