Camera Android N FileUrieExposedException

Camera Android N FileUrieExposedException,camera,file-uri,android-7.1-nougat,Camera,File Uri,Android 7.1 Nougat,伙计们,我的应用程序使用普通照相机拍照,我使用以下代码拍照 public void takepic(View view) { TextView schtitle = (TextView) findViewById(R.id.Sitename); String schname = schtitle.getText().toString(); String[] tokens = schname.split(" ");

伙计们,我的应用程序使用普通照相机拍照,我使用以下代码拍照

public void takepic(View view) {

        TextView schtitle = (TextView) findViewById(R.id.Sitename);
        String schname = schtitle.getText().toString();
            String[] tokens = schname.split(" ");
            String timeStamp = new SimpleDateFormat("dd-MM-yyyy-HH-mm-ss").format(new Date());
            String imageFileName = tokens[0] + "-" + timeStamp + ".jpg";
            TextView myAwesomeTextView = (TextView)findViewById(R.id.filetext);

          //in your OnCreate() method
          myAwesomeTextView.setText(imageFileName);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);    


                File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
                String name = imageFileName;
                File file = new File(path, name );
                outputFileUri = Uri.fromFile(file);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
                startActivityForResult(intent, TAKE_PICTURE); 


       } 
除了牛轧糖,这在所有地方都很好用

我理解他们在棉花糖中所做的,你现在需要权限,不能再使用文件URI了

我找不到任何关于如何用牛轧糖拍照的示例代码。有人能告诉我如何修改代码以允许这种情况发生吗

谢谢你的帮助


标记

问题是不再允许文件://uri

您必须使用FileProvider来代替此选项


看看这里:

问题是文件://uri不再被许可

您必须使用FileProvider来代替此选项


看看这里:

这里只是引用一下作为参考

我们现在有一个更新的文档,介绍如何使用带有文件uri的camera intent将拍摄的照片存储在android的培训部分


这里引用这句话作为参考

我们现在有一个更新的文档,介绍如何使用带有文件uri的camera intent将拍摄的照片存储在android的培训部分

##################加载项清单
       <provider
            android:name=".MyFileProvider"
            android:authorities="com.example.kushaalsingla.contentsharingdemo"
            android:grantUriPermissions="true"
            android:exported="false">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
        </provider>

##################filepath.xml########################
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <cache-path name="shared_images" path="images/"/>
</paths>

##################加载项清单
       <provider
            android:name=".MyFileProvider"
            android:authorities="com.example.kushaalsingla.contentsharingdemo"
            android:grantUriPermissions="true"
            android:exported="false">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
        </provider>

##################filepath.xml########################
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <cache-path name="shared_images" path="images/"/>
</paths>


使用
文件提供程序
:使用
文件提供程序