In my WebView it loads a webpage that includes a link to download an image with base64 data:
<a href="data:image/jpeg;base64,{base64data}" download="fileName.jpg" target="_blank">Download Image</a>
In Chrome when it's clicked, it will download the image as a JPG file. But it doesn't work in Android WebView.
Download Images using android webview indicates that I should use shouldOverrideUrlLoading()
to trigger the download.
It works with the image URL like http://.../image.jpg
. But for my base 64 data URL, it only works on Android versions below 4.4, the method shouldOverrideUrlLoading()
is never called on Android 4.4+ because it has to be a valid URL according to the Android API Guides.
So my question is, why data:image/jpeg;base64,{base64data}
is not a valid URL in this case? What should I do to trigger shouldOverrideUrlLoading()
for the base64 data URL? (Or even by making changes on the webpage)
Any suggestions would be highly appreciated, all I need is to save the image in Android.