first: if i remembered right there is a limit url length
second: there is lots of easier and cleaner way to download an image why you want to do this ?
I don't have much control over the webpage that has the link setup that way, so I was hoping to be able to find a way to download the image as-is without having to deal with getting the creator of the webpage to make any changes on their end.
I've tried to add a download listener to WebView, however the event is not raised for data uris. You can try it with your page:
B4X:
Sub Globals
Private WebView1 As WebView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
Dim dl As JavaObject
dl.InitializeNewInstance(Application.PackageName & ".main$MyDownloadListener", Null)
dl.RunMethod("set", Array(WebView1))
WebView1.LoadUrl("https://flaviocopes.com/data-urls/")
End Sub
Sub DownloadListener_Event (MethodName As String, Args() As Object) As Object
Log(MethodName)
Return Null
End Sub
Sub WebView1_OverrideUrl (Url As String) As Boolean
Log(Url)
Return False
End Sub
Sub WebView1_PageFinished (Url As String)
Log("page: " & Url)
End Sub
#if Java
public static class MyDownloadListener implements android.webkit.DownloadListener {
public void set(android.webkit.WebView wv) {
wv.setDownloadListener(this);
}
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimeType,
long contentLength)
{
BA.Log("Test");
}
}
#End If
If you see Test in the logs then the link click was detected.
Sub onDownloadStart (url As String, userAgent As String, contentDisposition As String, mimeType As String, contentLength As Long)
Log("url: " & url)
Log("userAgent: " & userAgent)
Log("contentDisposition: " & contentDisposition)
Log("mimeType: " & mimeType)
Log("contentLength: " & contentLength)
End Sub
Only the url returns a value (below) - the other vars are blank and contentLength returns -1: