美文网首页
调取相机的时候直接报 android.os.FileUriExp

调取相机的时候直接报 android.os.FileUriExp

作者: 皓皓amous | 来源:发表于2019-08-05 15:36 被阅读0次

1.在xml 文件中写入 filepaths.xml文件

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path path="Android/data/com.jsepc.omspf/" name="omsdisk_data"/>
    <external-path path="com.jsepc.omspf/" name="omsdisk_sdcard"/>
</paths>

2.在清单文件里面 androidManifest.xml 里面

 <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.jsepc.omspf.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths"
                />
        </provider>

3.使用FileProvider来获取文件的路径

Uri photoURI1 = FileProvider.getUriForFile(getApplicationContext(), "com.jsepc.omspf.fileprovider", file);//f

调取相机示例代码

    btn_camera.setOnClickListener(new View.OnClickListener() {
        @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                popupWindow.dismiss();

                File fileParent = new File( ConfigManager.PICPATHA)    ;
                if(!fileParent.exists()){
                    fileParent.mkdirs();
                }


                path = ConfigManager.PICPATHA + System.currentTimeMillis() + ".png";
                File file = new File(path);
                Uri photoURI1 = FileProvider.getUriForFile(getApplicationContext(), "com.jsepc.omspf.fileprovider", file);//f
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI1);
                intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0.2);
                startActivityForResult(intent, 10001);

            }
        });

相关文章

网友评论

      本文标题:调取相机的时候直接报 android.os.FileUriExp

      本文链接:https://www.haomeiwen.com/subject/pdhmdctx.html