Android Android.os.FileUri在Android N中暴露异常错误

Android Android.os.FileUri在Android N中暴露异常错误,android,Android,我在Orders文件夹的外部存储中有图像,我正试图使用intent将该图像共享给外部应用程序 File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Orders"); String filename = "OrderID.jpg"; File file = new File(file,filename); Intent intent = new Intent(Intent.ACTI

我在Orders文件夹的外部存储中有图像,我正试图使用intent将该图像共享给外部应用程序

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Orders");
String filename = "OrderID.jpg";
File file = new File(file,filename);
  Intent intent = new Intent(Intent.ACTION_SEND);
  intent.setType("image/*");
                intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
 intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(file));
                try {
                     startActivity(intent);
                } catch (android.content.ActivityNotFoundException ex) {

                }
我已经授予了加载应用程序本身的存储权限,但每次应用程序崩溃时我都会获得该权限

ndroid.os.FileUriExposedException: file:///storage/emulated/0/Orders/OrderID.jpg exposed beyond app through ClipData.Item.getUri()
谁能帮我解决这个问题吗? 我在谷歌上关注了很多帖子,但都没有用


当您要将文件共享给其他应用程序时,必须使用文件提供程序

检查

使用FileProvider.getUriForFile获取Uri,而不是代码中的
Uri.fromFile(file)

FileProvider.getUriForFile(this,"your_package.fileprovider",photoFile);

当您要将文件共享给其他应用程序时,必须使用文件提供程序

检查

使用FileProvider.getUriForFile获取Uri,而不是代码中的
Uri.fromFile(file)

FileProvider.getUriForFile(this,"your_package.fileprovider",photoFile);

@Man.当您要将文件共享到其他应用时,我已经为线索文件提供程序选择了答案。@Man.当您要将文件共享到其他应用时,我已经为线索文件提供程序选择了答案。请检查答案。检查答案。