B4A Library WebViewExtras

LBGroup

New Member
Licensed User
Longtime 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.
 

DonManfred

Expert
Licensed User
Longtime User
Hello Does anybody have an idea to do some file upload on kitkat ?
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.
 

oceanwanderlust

Member
Licensed User
Longtime 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:

warwound

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

Is that causing a problem?
 

oceanwanderlust

Member
Licensed User
Longtime 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:

warwound

Expert
Licensed User
Longtime User
Hmm...

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

B4X:
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.
 

Swissmade

Well-Known Member
Licensed User
Longtime User
Please place your Code in Code Insert so this will be better to read.
Like see below.

B4X:
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
 

oceanwanderlust

Member
Licensed User
Longtime 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
 

warwound

Expert
Licensed User
Longtime User
Depending on the version of WebViewExtras you are using the event passes different parameters.

With WebViewExtras2 the Sub parameters are:

B4X:
ReceivedError(ErrorCode As int, Description As String, FailingUrl As String)

A version i created for the FlingableWebView has parameters:

B4X:
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.
 

Croïd

Active Member
Licensed User
Longtime User
Please ! how can we insert the web text "class" in a EditText ?

For example : WebView1.LoadUrl("https://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:

FJS

Active Member
Licensed User
Longtime 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!
 

warwound

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

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:

B4X:
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:

B4X:
<!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>
 

Derek Johnson

Active Member
Licensed User
Longtime User

Something like:

B4X:
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:

Croïd

Active Member
Licensed User
Longtime User

Many Thanks Derek
 

Derek Johnson

Active Member
Licensed User
Longtime User
Derek I need to put additional ?

Sorry missing a couple of quote marks in the Javascript. This code works now.

B4X:
Sub WebView1_PageFinished (Url As String)

'find  <span class="title">Latest Versions</span>
    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].innerText )
    } else {
        B4A.CallSub('j_result', true, 'No element found' )
    }
"$
    WebViewExtras1.executeJavascript(WebView1,js)
End Sub

Sub j_result(result As String)
   Log("Result was " & result )
    EditText1.text= result
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…