简体   繁体   中英

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. I am using the string to save an image with 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:

/storage/emulated/0/Pictures/MyImages/Image1.jpg

Then I convert the filepath-string to an 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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM