为什么FileProvider.getUriForFile会导致运行时异常

时间:2016-11-21 15:25:44

标签: java android android-camera android-fileprovider

我按照Android Developers tutor进行拍摄并保存照片。 以下代码片段中对FileProvider.getUriForFile的调用会生成runtime error

例外 -

    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>

1 个答案:

答案 0 :(得分:0)

似乎问题在于在Manifest文件中定义提供程序。

在此处找到解决方案ANSWER

感谢ImagineThat