[英]Why do FileProvider.getUriForFile cause runtime exception
I follow the Android Developers tutor for taking and saving a picture. 我跟随Android Developers辅导老师拍摄和保存照片。 The call to
FileProvider.getUriForFile
in the following code fragment produce runtime error
. 下面的代码片段中对
FileProvider.getUriForFile
的调用会产生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 - 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 - 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 在这里找到一个解决方案ANSWER
Thanks to ImagineThat 多亏了ImagineThat
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.