B4A Library WebViewExtras

Discussion in 'Additional libraries, classes and official updates' started by warwound, Nov 7, 2011.

  1. bluedude

    bluedude Well-Known Member Licensed User

    Hi, is this working on API 21?

    I'm trying to use it after a long time and it does not seem so work anymore on Android 4.4.4.

    Which one is the latest version, 1.41?
     
  2. warwound

    warwound Expert Licensed User

    Version 1.41 is the latest version of the original WebViewExtras.
    WebViewExtras2 is available for download from my server (let me know if you want a link).

    Both libraries call the same android API methods but WebViewExtras2 is more complete - wrapping more of the API.

    Kitkat broke a number of WebView related functions.
    For example file uploads do not work in Kitkat - don't work in java and don't work in b4a.
    Lollipop has restored some functions but it's unclear exactly what works and what doesn't - unless you have many hours to research the subject.

    What exactly are you trying to do?
     
  3. bluedude

    bluedude Well-Known Member Licensed User

    Thanks warwound, got it working with Bootstrap, jQuery and your library. Pretty cool and responsive and hybrid.
     
  4. LBGroup

    LBGroup New Member Licensed User

    Hello, I'm in the process of porting over a web app that we use internally at our company from using the SureFox platform (basically locks our tablets in a browser mode locked on one web page) to writing a custom app that just wraps our internal web site in a WebView. So far all was going well until the file uploads wouldn't work. I found this library, installed it, and that brought back file uploads. The problem is that now it only allows files to be uploaded from Gallery or the Photos app. There isn't an option for Camera. In SureFox (or just the regular browser) Camera is an option. What do you advise?

    Hardware: Nexus 7 2014 with 4.3 Jellybean.
     
  5. Overlord

    Overlord New Member Licensed User

    Hello Does anybody have an idea to do some file upload on kitkat ?
     
  6. DonManfred

    DonManfred Expert Licensed User

    I´m not sure if this issue is related to webviewextras.
    Maybe you should create a new thread for it. Maybe the issue is related to webviewextras, maybe to the b4a webview itself.
     
  7. warwound

    warwound Expert Licensed User

  8. oceanwanderlust

    oceanwanderlust Member Licensed User

    My app loads a webpage, then uses JavaScript to inspect the state of the page or occasionally automatically push a button on the webpage. I'm using a timer to automatically reload the webpage every few minutes. The program runs fine for a while, but then eventually I quit receiving _PageFinished events even though Timer3 keeps reloading the page. Why do I suddenly stop receiving _PageFinished messages? Am I reloading the page correctly?

    joe

    EDIT: removing code because unrelated to solution
     
    Last edited: Aug 5, 2015
  9. warwound

    warwound Expert Licensed User

    What does your ProcessHTML sub do?
    Does it modify the user interface (views etc)?

    Is that causing a problem?
     
  10. oceanwanderlust

    oceanwanderlust Member Licensed User

    ProcessHTML checks if the page is properly displaying one of two webpages, if not, it starts yet another Timer2 to try to reload the page again quickly and maybe fiddle with the wifi. My problem is that eventually _PageFinished is not called so ProcessHTML never gets called, even though Timer3 IS being called and is supposed to be reloading WebView1 every few minutes.

    EDIT:

    1) removing code because unrelated to solution

    Summary/Solution: As my app demonstrated after many Reloads, WebView simply fails to call PageFinished. I had already injected javascript into the page, so Warwound's solution to use "javascript Location reload() method to reload" reliably reloads it infinitely.
     
    Last edited: Aug 5, 2015
  11. warwound

    warwound Expert Licensed User

    Hmm...

    Well if your ProcessHTML Sub causes any part of the user interface to be modified then you need to change your javascript:

    Code:
    Javascript="B4A.CallSub('ProcessHTML', true, document.documentElement.outerHTML)"
    I've changed the second parameter to true from false.
    That's worth trying - it won't take long to change and might be a quick fix.

    Otherwise i'm not sure where to look next.
    You could try using the javascript Location reload() method to reload the webpage instead of using the WebView Reload method.

    I suspect there is no error in your code and that the WebView is just failing after the webpage has been reloaded many times.
     
    oceanwanderlust likes this.
  12. swissmade

    swissmade Active Member Licensed User

    Please place your Code in Code Insert so this will be better to read.
    Like see below.

    Code:
    Sub ProcessHTML(FlingableWebView1 As FlingableWebView, Html As String)
    If Html.Contains(ACTIVE_STATE_STRING) = True Then
    Timer1.Enabled = 
    False
    Else If Html.Contains(INACTIVE_STATE_STRING) = True Then
    If Timer1.Enabled = False Then
    Timer1.Enabled = 
    True    'this timer does a JavaScript Click() on the page in about an hour...
    End If
    Else
    Log("PAGE ERROR")
    Timer2.Enabled=
    True  'this timer tries to refresh the webpage in ~10 seconds and also fiddles with the wifi
    End If
    End Sub


    Thanks
     
  13. oceanwanderlust

    oceanwanderlust Member Licensed User

    Why am I getting a runtime "signature does not match expected signature" for HandleDoorbellWebview_ReceivedError? I think this might be an interesting message to catch, and also shows that I might be misunderstanding something about webview vs webviewclient events.

    joe
     
  14. warwound

    warwound Expert Licensed User

    Depending on the version of WebViewExtras you are using the event passes different parameters.

    With WebViewExtras2 the Sub parameters are:

    Code:
    ReceivedError(ErrorCode As int, Description As String, FailingUrl As String)
    A version i created for the FlingableWebView has parameters:

    Code:
    ReceivedError(FlingableWebView1 As FlingableWebView, ErrorCode As int, Description As String, FailingUrl As String)
    The solution is to use the b4a IDE autocomplete to see what parameters are required for the version you are using.

    In your activity module start a new line.
    Type Sub then space and then press the TAB key.
    Select DefaultWebViewClient from the drop down liat and then select the ReceivedError event.
    The IDE will create the Sub with the parameters required.
     
    zztop likes this.
  15. oceanwanderlust

    oceanwanderlust Member Licensed User

    Thankyou for taking the extra time to write out the IDE instructions. That was very helpful.
     
  16. Croïd

    Croïd Active Member Licensed User

    Please ! how can we insert the web text "class" in a EditText ?

    For example : WebView1.LoadUrl("http://www.b4x.com/index.html")

    WebViewExtras1.executeJavascript(WebView1, "B4A.CallSub('Javascript', true,document.title)")

    Edittext Show = <title>B4X - The simple way to develop native Android &amp; iOS apps</title>


    It is possible read : <span class="title">Latest Versions</span>
     
    Last edited: Jun 21, 2015
  17. FJS

    FJS Active Member Licensed User

    Hello everybody,

    I am trying to use the following html code:

    <script type="text/javascript" src="http://ad.leadboltads.net/show_app_ad.js?section_id=xxxxxxxxx"></script>

    As you can see, the idea is showing ads,

    with a webview like:

    WebView1.LoadHtml("<script type="text/javascript" src="http://ad.leadboltads.net/show_app_ad.js?section_id=xxxxxxxxx"></script>")

    however it has a syntax error... and only the text apears:(

    Please, any expert could you tell me how white right the information?

    Thank you!
     
  18. warwound

    warwound Expert Licensed User

    Doesn't the IDE give you a syntax error on that line with those double quotes within a string?
    I'd try something like this:

    Code:
    WebView1.LoadHtml("<script type='text/javascript' src='http://ad.leadboltads.net/show_app_ad.js?section_id=xxxxxxxxx'></script>")
    If that still fails then you probably need to pass a valid page of HTML to the LoadHtml method instead of a single <script> tag:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <script 
    type='text/javascript' src='http://ad.leadboltads.net/show_app_ad.js?section_id=xxxxxxxxx'></script>
    </head>
    <body>
    </body>
    </html>
     
  19. Derek Johnson

    Derek Johnson Active Member Licensed User

    Something like:

    Code:
    Sub Webview1_PageFinished (Url As String)
        
    '...
        Get1stElementByClass("title")

    End Sub

    Sub Get1stElementByClass(id As String)

    Dim js As String=$"
        var elems = document.getElementsByClassName('${
    id}');
        if (elems.length>0) {
            B4A.CallSub('j_result', true, elems[0].innerHTML )
        } else {
            B4A.CallSub('j_result', true, '' )
        }
    "$

        WebViewExtras1.executeJavascript(WebView1,js)
    End Sub


    Sub j_result(result As String)
        
    Log("Result was " & result )
        
    'edittext1.text=result

    End Sub
    I've corrected my original post having checked it out with an example.
     
    Last edited: Jun 21, 2015
    TWCoder and Croïd like this.
  20. Croïd

    Croïd Active Member Licensed User

    Many Thanks Derek
     
Loading...
  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