Android Question WV_OverrideURL event not being triggered for a Data:Base64 link

Discussion in 'Android Questions' started by JohnC, Aug 6, 2019.

  1. JohnC

    JohnC Well-Known Member Licensed User

    My app needs to display an image from a webpage in which the link on the webpage is the actual data of the image.

    In other words, when I hover over the link on the webpage, and select "Copy Link Address" the clipboard then contains this:


    (where the "........" is actually a bunch of base64 encoded data of the image that I removed from the above line so it wont take up the entire screen.

    If I click this link in a desktop Firefox browser, it will prompt me to "Open" the file(data) with an image viewer or to save the file to disk.

    In order to display the image from within my app, I first need to download the data in that link.

    But, when I click the link in a webview, the wv_overrideurl event never triggers - webview just sits there with a dumb look on its face.

    Anyone have an idea why the event doesn't trigger for this special type of "data:" link?
  2. Devv

    Devv Active Member Licensed User

    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 ?
  3. JohnC

    JohnC Well-Known Member Licensed User

    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.
  4. Devv

    Devv Active Member Licensed User

    can you paste a demo code that view the problem ?
  5. Erel

    Erel Administrator Staff Member Licensed User

    You can download the html page with OkHttpUtils2 and find this data in the downloaded page.
  6. JohnC

    JohnC Well-Known Member Licensed User

    But then how can I detect when the user wants to see the image and clicks on the link?
  7. JohnC

    JohnC Well-Known Member Licensed User

    The webpage is behind a paid firewall, so I cant get the source for it :(

    It looks like Webview is not designed to detect clicks on links that start with "data:"
  8. DonManfred

    DonManfred Expert Licensed User

    Webview is designed to detect clicks on "a" Tags.

    Firefox did detect the click on an img Tag which is not filled by a src url but by src-data.
    If is a side-feature of Firefox.
    JohnC likes this.
  9. Erel

    Erel Administrator Staff Member Licensed User

    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:
    Sub Globals

    Private WebView1 As WebView
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    Dim dl As JavaObject
    Application.PackageName & ".main$MyDownloadListener"Null)
    End Sub

    Sub DownloadListener_Event (MethodName As String, Args() As Object) As Object
    Return Null
    End Sub

    Sub WebView1_OverrideUrl (Url As StringAs Boolean
    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) {
     public void onDownloadStart(String url, String userAgent,
                                    String contentDisposition, String mimeType,
                                    long contentLength)
    #End If
    If you see Test in the logs then the link click was detected.
    JohnC likes this.
  10. JohnC

    JohnC Well-Known Member Licensed User

    Thanks Erel, I will give that a try!
  11. JohnC

    JohnC Well-Known Member Licensed User

    Thanks for the info on the "a" tag - I did not know that.
  12. JohnC

    JohnC Well-Known Member Licensed User

    OK, I got the "Test" in the log.

    So I modified the Java (I am just starting to understand Java) to this (based on your java code in this thread:

    public void onDownloadStart(String url, String userAgent,
    String contentDisposition, String mimetype,
                                    long contentLength)
    "ondownloadstart", url, userAgent, contentDisposition, mimetype, contentLength);
    And added this event:

    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:


    So now I can work with that to decode the data and display the image.

    Thanks Erel!
    Last edited: Aug 7, 2019
    Erel and DonManfred like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice