相关疑难解决方法(0)

android.os.FileUriExposedException:file:///storage/emulated/0/test.txt通过Intent.getData()暴露在app之外

当我尝试打开文件时,应用程序崩溃了.它可以在Android Nougat下运行,但在Android Nougat上它会崩溃.当我尝试从SD卡打开文件而不是从系统分区打开文件时,它只会崩溃.一些许可问题?

示例代码:

File file = new File("/storage/emulated/0/test.txt");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "text/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent); // Crashes on this line
Run Code Online (Sandbox Code Playgroud)

日志:

android.os.FileUriExposedException:file:///storage/emulated/0/test.txt通过Intent.getData()暴露在app之外

编辑:

在定位Android Nougat时,file://不再允许使用URI.我们应该使用content://URI代替.但是,我的应用程序需要打开根目录中的文件.有任何想法吗?

android android-file android-7.0-nougat

682
推荐指数
15
解决办法
38万
查看次数

如何在启动ACTION_SEND意图时附加位图

我有这个代码:

 Intent intent = new Intent(); 
 intent.setAction(Intent.ACTION_SEND); 
 startActivity(intent); 
Run Code Online (Sandbox Code Playgroud)

哪个将成功在Android上启动消息应用程序.

但是,如何在启动意图时附加Bitmap对象?

我已经阅读了http://developer.android.com/reference/Android/content/Intent.html,我需要的东西就是EXTRA_STREAM,就像这样:

intent2.putExtra(Intent.EXTRA_STREAM,_uri);

但我的情况是,我有一个Bitmap对象的引用,而不是Bitmap的URI.

请告诉我如何附加Bitmap对象?

android mms bitmap

18
推荐指数
2
解决办法
3万
查看次数

Android N 中的 android.os.FileUriExposedException 错误

我的订单文件夹中的外部存储中有图像,并且我正在尝试使用意图将该图像共享到外部应用程序

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

https://github.com/tungdx/android-media-picker/issues/11

https://github.com/MLSDev/RxImagePicker/issues/13

android

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×3

android-7.0-nougat ×1

android-file ×1

bitmap ×1

mms ×1