[英]Android: File not found on external storage
I have a string filename which is a path to the pictures folder on external storage for android deveices. 我有一个字符串文件名 ,它是android设备在外部存储设备上的pictures文件夹的路径。 I am using the string to save an image with opencv.
我正在使用字符串使用opencv保存图像。 Then I want to send a share intent to share the saved image with other apps.
然后,我想发送共享意图,以与其他应用程序共享保存的图像。
Highgui.imwrite(filename, Image);
Log.d("WRITEPATH", filename);
In LogCat I get for WRITEPATH: 在LogCat中,我得到了WRITEPATH:
/storage/emulated/0/Pictures/MyImages/Image1.jpg
/storage/emulated/0/Pictures/MyImages/Image1.jpg
Then I convert the filepath-string to an uri: 然后,我将filepath-string转换为uri:
Uri lastsavedUri=Uri.parse(new File(filename).toString())
And send my share intent: 并发送我的分享意向:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, SavedImages);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share images to.."));
SavedImages is a ArrayList containing multiple lastsavedUri SavedImages是一个包含多个lastsavedUri的ArrayList
Unfortunately no app can find the images I am trying to share. 不幸的是,没有应用程序可以找到我要共享的图像。 For example Gmail crashes after clicking send mail and I receive a logcat error
例如,点击发送邮件后Gmail崩溃了,我收到一个logcat错误
10-07 10:19:47.265: E/Gmail(26264): Unable to get orientation of thumbnail /storage/emulated/0/Pictures/MyImages/Image1.jpg 10-07 10:19:47.265: E/Gmail(26264): java.io.FileNotFoundException: No content provider: /storage/emulated/0/Pictures/MyImages/Image1.jpg
10-07 10:19:47.265:E / Gmail(26264):无法获取缩略图的方向/storage/emulated/0/Pictures/MyImages/Image1.jpg 10-07 10:19:47.265:E / Gmail(26264 ):java.io.FileNotFoundException:没有内容提供者:/storage/emulated/0/Pictures/MyImages/Image1.jpg
Why can I save my images using the filepath string but why can't I share the saved images? 为什么可以使用文件路径字符串保存图像,但是为什么不能共享保存的图像? Is the path not correct and how do I get the correct path to my saved images?
路径不正确吗?如何获得保存图像的正确路径?
I tried 我试过了
File saveFile = new File(filename);
SavedImages.add(Uri.fromFile(saveFile));
instead of 代替
Uri lastsavedUri=Uri.parse(new File(filename).toString())
SavedImages.add(lastsavedUri);
and now it is working. 现在它正在工作。 I don't understand why, but it works.
我不明白为什么,但是可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.