我按照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>