Android Question Webview reading values with which page was opened

Juzer Hussain

Active Member
Licensed User
Longtime User
Hi,

In webview user navigates to a new page.
This page is called with certain paramaters. I want to read them using WebviewExtras on PageFinished.

1. Do we get url in PageFinished.
2. How do we read the variables (their name we know)

Pls give some clue.

Thanks
Juzer
 

drgottjr

Expert
Licensed User
Longtime User
1) pagefinished will give you the url of the
loaded page. in typical b4a event style,
the url is returned as a parameter in the
pagefinished event. look at the b4a
webview documentation. it's very clear.
there are some restrictions (not related to
b4a). pagefinished doesn't necessarily
give you what you're looking for.

2) when pagefinished fires, you execute
a javascript using webviewextras to
capture the values you're looking for
(if available). this can work without
trouble.

a very, very simple example would be:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    webview.Initialize("wv")
    Activity.AddView(webview,0%x,0%y,100%x,100%y)
    webview.JavaScriptEnabled = True
   
    webviewextras.addJavascriptInterface(webview, "wvx")
    webviewextras.addWebChromeClient( webview, "chrome")
   
    webview.LoadUrl("some_website")  ' HTTPS HTTPS HTTPS not http
End Sub


Sub wv_PageFinished (Url As String)
    Log(Url & " loaded...")
    Dim script As String = "alert(" & "SOME_VARIABLE_THAT_IS_KNOWN" & ");"
    webviewextras.executeJavascript(webview, script)
End Sub

if the scheme is not HTTPS, you will have to change the manifest.

to actually capture some webpage variable as a b4a variable, you need
to inject more (not terribly difficult). simply to look at some webpage
variable as in the example, an alert will work. but you have to have
knowledge of how and when the variable you are looking for is assigned.
it may have nothing to do with pagefinished. a lot depends on exactly
how the page is generated.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
Upvote 0
Top