Reputation: 8787
how can i detect when a WebView website has loaded successfully with NO errors. I tried onPageFinished
but it still get called when internet connection fails. I want to make my views visible again when the website has loaded successfully with no errors (and no "Website not available")
This is what I am using currently that even calls when the request had an error (e.g. no internet etc.)
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
view?.visibility = View.VISIBLE
rootView.loadingSpinner.visibility = View.INVISIBLE
}
Upvotes: 0
Views: 452
Reputation: 2982
One way to do this: Use this (deprecated but still functional) api. Will be called for the main url you are loading, not every web resource like the newer version. This should take care of both no internet connection and http error responses.
@SuppressWarnings("deprecation")
override fun onReceivedError(view: WebView, errorCode: Int, description: String, failingUrl: String) {
//hide it, etc...
// println("ON receive error: $errorCode $description $failingUrl")
}
Upvotes: 1