Reputation: 195
recently I have implemented a WebView for my app. I have override the onPageFinished
function of WebViewClient and it works fine most of the time. But when I tested it on real device (Samsung S10), and turned off the internet connection, the code from onPageFinished
is not called. In fact, all functions I overrided in WebViewClient
are not called.
I have tested on emulators and it worked as intended. But on my physical device, the code is not executed. Also, the error code is net:ERR_FAILED
instead of net:ERR_INTERNET_DISCONNECTED
.
So what is the problem? Did I do something wrong?
Here is my code
webView = WebView(requireContext()).apply {
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
\\ Do something
}
override fun onReceivedError(
view: WebView?,
request: WebResourceRequest?,
error: WebResourceError?
) {
super.onReceivedError(view, request, error)
\\ Do something
}
}
loadUrl(url)
}
Upvotes: 0
Views: 248