当我尝试打开文件时,应用程序崩溃了.它可以在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代替.但是,我的应用程序需要打开根目录中的文件.有任何想法吗?
我有这个代码:
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对象?
我的订单文件夹中的外部存储中有图像,并且我正在尝试使用意图将该图像共享到外部应用程序
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