I am trying to load a url in android app webview but it's failing I don't know what's the exact problem. onPageStared() and method called, onReceiveError method not called, onPageFinished method is also called. Below is my code -
@SuppressLint("SetJavaScriptEnabled")
private fun setupWebView() {
webviewViewModel.loadingVisibility.value = View.VISIBLE
val webView = binding.webView
webView.settings.javaScriptEnabled = true
webView.settings.loadWithOverviewMode = true
webView.settings.useWideViewPort = true
webView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
view?.loadUrl(webviewViewModel.url)
return true
}
override fun onPageFinished(view: WebView?, url: String?) {
webviewViewModel.loadingVisibility.value = View.GONE
}
}
webView.loadUrl(webviewViewModel.url)
}
and URL I'm using is - http://192.168.10.22:4200/bigday/terms-and-conditions
Help me for what I'm missing.
After 2-3 days search I got the solution by adding
webView.settings.domStorageEnabled = true
@SuppressLint("SetJavaScriptEnabled")
private fun setupWebView() {
webviewViewModel.loadingVisibility.value = View.VISIBLE
val webView = binding.webView
webView.settings.javaScriptEnabled = true
webView.settings.javaScriptCanOpenWindowsAutomatically = true
webView.settings.domStorageEnabled = true
webView.settings.loadWithOverviewMode = true
webView.settings.useWideViewPort = true
webView.settings.allowContentAccess = true
webView.webChromeClient = WebChromeClient()
webView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
view?.loadUrl(webviewViewModel.url)
return true
}
override fun onPageFinished(view: WebView?, url: String?) {
webviewViewModel.loadingVisibility.value = View.GONE
}
}
webView.loadUrl(webviewViewModel.url)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.