thunderbird / thunderbird-android

Thunderbird for Android – Open Source Email App for Android (fka K-9 Mail)
https://thunderbird.net/mobile
Apache License 2.0
10.98k stars 2.51k forks source link

Download external images #4995

Open cketti opened 4 years ago

cketti commented 4 years ago

Describe the bug Long-pressing an external image in an HTML message offers "Download image" as an option. This uses DownloadManager to download the file. But the documentation states:

By default, downloads are saved to a generated filename in the shared download cache and may be deleted by the system at any time to reclaim space.

That means users can't actually get to the file other than through the notification that will open the file for viewing when clicked.

Expected behavior Prompt the user for a storage location. Download and write the file to that location.

Environment:

Note: I don't want us to request the WRITE_EXTERNAL_STORAGE permission just to be able to use DownloadManager. So we'll probably have to download the image ourselves. Ideally we'll use an existing library for that. Suggestions welcome.

GNUDimarik commented 3 years ago

@cketti may be we able to use Picasso for loading Images to app when we want to do that. What do you think?

cketti commented 3 years ago

@GNUDimarik Picasso is a library that deals with displaying images. This issue is about downloading images and saving them to storage, not displaying them.

This requires:

Ideally there would also be a way to pause and resume or cancel an ongoing download.

GNUDimarik commented 3 years ago

@cketti Picasso has auto caching also. But I'm not sure we able to control it. But I got your point. If you don't want to use WRITE_EXTERNAL_STORAGE permission then it's possible to save it via ContentProvider in db. Not sure if that's a goot idea ... Please let me know what do you think?

kosmoz commented 3 years ago

To improve the current behaviour at least temporarily you could still use DownloadManager but save to the public downloads directory using setDestinationInExternalPublicDir. This does not allow the user to pick a location but it does not require WRITE_EXTERNAL_STORAGE (since k-9 targets API level 29, afaict) and at least the file can be accessed by the user.

https://developer.android.com/reference/android/app/DownloadManager.Request#setDestinationInExternalPublicDir(java.lang.String,%20java.lang.String)