当前位置: 首页 > 知识库问答 >
问题:

Android N FileUriExposedException

呼延卓
2023-03-14
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); 


       } 

有什么需要帮忙的吗

标记

共有1个答案

贝镜
2023-03-14

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

相反,您必须使用FileProvider。

看看这里:https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en

 类似资料:

相关问答

相关文章

相关阅读