The site (example) www.xxxxxxxxx.com is duly registered with the NIC (Network Information Center) but has not yet published anything except the following page :
<html><head></head><body></body> </html>
However I don't know the name of this page (www.xxxxxxxxx.com/index.htm or www.xxxxxxxxx.com/index.html or www.xxxxxxxxx.com/default.html or .... I don't know). I cannot download it with a Job.
I would like to be notified with a long loud ring when this site posts something.
I quickly created an app that every X seconds loads the site mentioned in a webview and then examines the content of the webview itself.
If the length of the loaded page exceeds 39 bytes it should mean that the site has published a significant page and therefore the alarm should go off.
However, it happens that after about ten minutes a page appears indicating that this page is not available with a message: ERR_TIMED_OUT.
The length of this HTML page is 2278 bytes.
It would seem logical to think that the site actually posts something meaningful when my app reports a length> 2278 bytes (or maybe different from both 39 and 2278).
I obviously don't have the chance to test this app too much so I ask if the approach I invented is valid or if there is a better one.
This is the code (synthesized) I used.
<html><head></head><body></body> </html>
However I don't know the name of this page (www.xxxxxxxxx.com/index.htm or www.xxxxxxxxx.com/index.html or www.xxxxxxxxx.com/default.html or .... I don't know). I cannot download it with a Job.
I would like to be notified with a long loud ring when this site posts something.
I quickly created an app that every X seconds loads the site mentioned in a webview and then examines the content of the webview itself.
If the length of the loaded page exceeds 39 bytes it should mean that the site has published a significant page and therefore the alarm should go off.
However, it happens that after about ten minutes a page appears indicating that this page is not available with a message: ERR_TIMED_OUT.
The length of this HTML page is 2278 bytes.
It would seem logical to think that the site actually posts something meaningful when my app reports a length> 2278 bytes (or maybe different from both 39 and 2278).
I obviously don't have the chance to test this app too much so I ask if the approach I invented is valid or if there is a better one.
This is the code (synthesized) I used.
B4X:
Sub Activity_Create(FirstTime As Boolean)
URL1="www.xxxxxxxxxxxxx.com"
Timer1.Initialize("Timer1",300000)
WebView1.Initialize("WB1")
Activity.AddView(WebView1, 0,250dip,100%x,100%y-250dip)
WebView1.JavaScriptEnabled = True
WebViewExtras1.Initialize(WebView1)
WebViewExtras1.JavaScriptEnabled = True
JS.Initialize
WebViewExtras1.AddJavascriptInterface(JS, "B4A")
end sub
Sub WB1_PageFinished(URL As String)
ToastMessageShow("Load " & URL ,False )
Dim script As String
script = "B4A.CallSub('ProcessHTML', true, document.documentElement.outerHTML)"
WebViewExtras1.ExecuteJavascript(script)
End Sub
Sub LoadPageX
'--- delete cache
Dim o As Reflector
o.Target = WebView1
o.RunMethod2("clearCache","True","java.lang.boolean")
WebView1.LoadUrl(URL1)
Sleep(0)
End Sub
Sub Timer1_tick
LoadPageX
End Sub
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
Dim sf As StringFunctions
Dim L As Long
sf.Initialize
LogColor(Html,Colors.blue )
L=sf.Len(Html)
LogColor("L=" & L,Colors.Blue)
If L>2300 Then
' VERY LONG BEEP
End If
End Sub