Couldn't find meta-data for provider with authority xxx.fileprovider
在调用相机拍照的时候出现了这个问题,Android 7(24)以上调用相机的完整操作是:
1、调用相机方法:
Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File("path", "文件名")));
startActivityForResult(openCameraIntent, camera_result);
} else {
Uri imageUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileprovider",
new File("path", "文件名"));
openCameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(openCameraIntent, camera_result);
}
2、在AndroidManifest.xml中配置:
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="包名.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
3、在res/xml下创建文件file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<paths>
<external-path
name="files_root"
path="Android/data/包名/" />
<external-path
name="external_storage_root"
path="." />
</paths>
<!--<root-path/> :代表设备的根目录new File("/")-->
<!--<files-path/> : 代表context.getFilesDir()-->
<!--<cache-path/> : 代表context.getCacheDir()-->
<!--<external-path/> : 代表Environment.getExternalStorageDirectory()-->
<!--<external-files-path/> : 代表context.getExternalFilesDirs()-->
<!--<external-cache-path/> : 代表getExternalCacheDirs()-->
<!--path节点支持name和path两个属性,配置了path属性就相当于在相应路径下子目录,-->
</resources>