为什么 FileProvider.getUriForFile 导致运行时异常
Why do FileProvider.getUriForFile cause runtime exception
我按照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>
似乎问题出在清单文件中定义提供者。
在这里找到了解决方案
我按照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>
似乎问题出在清单文件中定义提供者。
在这里找到了解决方案