I have seen answers to detecting when a URL has finished loading, which I need to know.. but I also need to know if the load was successful.
I need to know this as I am loading an HTML interstitial advert and if it is not loaded then I don't want to display it. I can make my own WebClient
and detect onPageFinished
, but I noticed that if I switched my internet off, I would still see the onPageFinished
being called. So how do I detect that the URL if both finished AND successful?
EDIT: Looking at ObAt's suggestion, and combining that with the most popular answer to this SO question, I'm still a bit stuck. It seems that when I have my internet switched off, the contents of the WebView after onPageFinished
appears to be (with my section_id number changed to 9999):
<head><head><script type="text/javascript" src="http://ad.leadboltads.net/show_app_ad.js?section_id=9999"></script></head><body></body></head>
This does not show any obvious errors.
EDIT: Just noticed that I'm doing a LoadData
rather than a LoadUrl
, I don't know if this makes any difference.
EDIT: If my internet is on and the ad loads successfully, then an example contents of the webview is this:
<iframe name="ap_iframe" width="300" height="250" frameborder="0" src="http://ad.leadboltads.net/show_app_ad?section_id=9999&lang=en-GB&scr_w=480&scr_h=800&
url=data%3Atext%2Fhtml%2C%3Cscript%20type%3D%22text%2Fjavascript%22%20src%3D%22http%3A%2F%2Fad.leadboltads.net%2Fshow_app_ad.js%3Fsection_id%__HIDDEN__script%253E&
referer=" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no"></iframe></body></head>
So, I can now see differences between the two states... and perhaps I could just do a search for "iframe" or "width" or anything I might expect in the successfully loaded page that isn't in the failed page... but it feels like a very non-general and unsatisfactory answer.