调用相机拍照奔溃

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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值