我的订单文件夹中的外部存储中有图像,并且我正在尝试使用意图将该图像共享到外部应用程序
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) {
}
Run Code Online (Sandbox Code Playgroud)
我已授予加载应用程序本身的存储权限,但每次应用程序崩溃时我都会得到
ndroid.os.FileUriExposedException: file:///storage/emulated/0/Orders/OrderID.jpg exposed beyond app through ClipData.Item.getUri()
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我解决这个问题吗?我在谷歌上关注了很多帖子但没有用
android.os.FileUriExposedException:file.jpg 通过 ClipData.Item.getUri() 暴露在应用程序之外
https://github.com/react-native-community/react-native-share/issues/185
当您想要将文件共享给其他应用程序时,您必须使用FileProvider 。
检查https://developer.android.com/training/secure-file-sharing/setup-sharing。
使用FileProvider.getUriForFile来获取 Uri 而不是Uri.fromFile(file)在代码中。
FileProvider.getUriForFile(this,"your_package.fileprovider",photoFile);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13584 次 |
| 最近记录: |