【问题标题】:Why do FileProvider.getUriForFile cause runtime exception为什么 FileProvider.getUriForFile 会导致运行时异常
【发布时间】:2016-11-22 19:54:04
【问题描述】:

我关注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>

【问题讨论】:

  • 请编辑您的问题并提供您的file_paths.xml 文件的内容。另外,请说明您是如何为photoFile 创造价值的。

标签: java android android-camera android-fileprovider


【解决方案1】:

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

在这里找到解决方案ANSWER

感谢ImagineThat

【讨论】:

    猜你喜欢
    • 2010-09-18
    • 2017-05-27
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    相关资源
    最近更新 更多