Piasy / BigImageViewer

Big image viewer supporting pan and zoom, with very little memory usage and full featured image loading choices. Powered by Subsampling Scale Image View, Fresco, Glide, and Picasso. Even with gif and webp support! 🍻
MIT License
3.98k stars 400 forks source link

Method saveImageIntoGallery() generate ".0" as file extension on Android >= 10. #208

Closed SongpolR closed 3 years ago

SongpolR commented 3 years ago

I try to use saveImageIntoGallery() to save an image to the device's gallery, it works fine on android < 10 with a timestamp as a filename and correct extension. However, when I try on a device with android >= 10, the filename was not the timestamp anymore and the extension will be ".0" which I think came from the filename on the cache.

This problem occurred on Samsung and OPPO devices, but not on the Pixel emulators(because it appends .jpg to the saved filename)

Piasy commented 3 years ago

The cache filename is determined by image loader —— Fresco or Glide, if you need better name, you need handle it on your own.

SongpolR commented 3 years ago

Thanks for the explanation of the filename. However, I investigate more about my problem, and I figure out that I explain it wrong. The problem is not about the filename anymore, but about the file extension. All the saved files(no matter from cache or not) does not have any file extension. To open it, I have to manually append the file extension(like .jpg or .png) by renaming. I try on the demo project and got this issue as well. Any suggest?

Piasy commented 3 years ago

I mean file name by the full name, including the file extension as I explained in #195.

SongpolR commented 3 years ago

Where should I put the logic to handle the filename? ImageLoaderCallback when the cache hit/miss?

Piasy commented 3 years ago

If you want to rename the saved image file, you can do it in ImageSaveCallback.

SongpolR commented 3 years ago

Thanks, now I can save the file with the name and extension as I was expecting. But, a new problem occurred instead. I got onFail callback from ImageSaveCallback(even though it succeeded before or not, when it failed for one time, it will keep failing all the time after that) and stack trace print something like:

android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: files._data (code 2067 SQLITE_CONSTRAINT_UNIQUE)

Any clue about this issue?

SongpolR commented 3 years ago

Oh...I think I can figure out, I have to remove the content file from MediaStore after successfully save the image(according). Please correct me if I misunderstand or it has a better way to do?

Piasy commented 3 years ago

That sounds strange, I think adding the same image twice to the gallery should be fine, but maybe I'm wrong.

SongpolR commented 3 years ago

It's fine on the demo project, but I don't why it is not working on my project. Anyway thanks for your support.