Hi Cableguy,
We must be following each other along the same lines as I have just done this because of a problem I have using HttpUtils due to a circular redirection.
I use the JSInterface and it works really well, the app that I am using it with has a webview but the webview is only inititilised but never loaded into the activity as I do not need to see the site just get data from the HTML.
have a look at this post from Martin who wrote the JSInterface
The code that I use has 2 variations ,
javascript="var logonForm=document.forms.logonForm;logonForm.username.value='yourname';logonForm.password.value='yourpassword';logonForm.submit();"
myInterface.execJS(webview1, javascript)
javascript="document.all.Id.value='yourname';document.all.Pass.value='yourpassword';dothejob();"
myInterface.execJS(webview1, javascript)
the difference between the two is the way the two sites are coded, the first one is,
<tbody>
<tr>
<td class="nowrap"><label for="username">Username:</label></td>
<td class="txtpad">
<input class="txt" id="username" name="username" type="text" />
</td>
</tr>
<tr>
<td class="nowrap"><label for="password">Password:</label></td>
<td class="txtpad">
<input class="txt" id="password" onfocus="g_fFcs=0" type="password" name="password" />
</td>
</tr>
<tr>
<td class="nowrap"> </td>
<td class="txtpad" colspan="2">
<input class="btn" onmousedown="this.className='btnOnMseDwn'" id="SubmitCreds" onmouseover="this.className='btnOnMseOvr'" onclick="clkLgn()" onmouseout="this.className='btn'" type="submit" value="Log On" name="SubmitCreds" />
</td>
</tr>
</tbody>
you can see where I got the field name from and also the button has a 'submit' type, the form also had a title of
<form action="/CookieAuth.dll?Logon" method="post" id="logonForm" autocomplete="off">
and that is where I got the ID of "logonForm"
The second one did not have a form ID and had two buttons with the same type.
<input id="Id" type="text" onkeypress="Enter_Web(event)" onkeydown="KeyIsDown(true)" maxlength="10" size="10">
<br>
<b>
<input id="Pass" type="password" onkeypress="Enter_Web(event)" onkeydown="KeyIsDown(false)" maxlength="8" size="10">
<br>
<br>
<input id="B1" class="login" type="button" name="B1" value="Login" onclick="dothejob()" style="color: blue;">
<input id="CLS" class="login" type="button" name="CLS" value="Clear" onclick="clearform()" style="color: blue;">
so with a small bit of trial and error "document.all." worked to reference the form and I activated the on click javascript directly with "dothejob()".
When the web page is loaded the "Sub web_PageFinished (Url As String)" will run and this is where you put your code to handle the data.
The only complication is getting the data from the webview after it has loaded, this is where HttpUtils wins (if you can get it to work) as once the 'post' has returned you then do a 'get' to load the HTML of the site. WebView has no function to get its loaded HTML (not sure if this is a limitation of Android or a lacking facility of B4A "Put it on the wishlist Erel" We can CaptureBitmap but cannot get the underlying HTML this is where JSInterface comes to the rescue again. This makes the javascript work in the other direction and sends the HTML to your B4A app
myInterface.addJSInterface(WebView1, "B4A")
Dim jsStatement As String
jsStatement="B4A.CallSub('processHTML', document.documentElement.outerHTML)"
Log("PageFinished: "&jsStatement)
myInterface.execJS(WebView1, jsStatement)
Sub processHTML(html As String)
'This is the Sub that we'll get the web page to send it's HTML content to
'Log may truncate a large page so you'll not see all of the HTML in the log but the 'html' String should still contain all of the web page HTML
PageContent = html
Log(PageContent)
End Sub
The only complication is you might get a thread execption as the processHTML is generated on a different thread then the main app (I think) so needs to be handled carefully. As I said earlier if you can get HttpUtils to work then this is by far the better and much quicker way to go.
Edward