Issue
I created an android WebView and open my website who server with https and authentication redirection anyway this work successfully in all of modern browsers like opera, chrome, Firefox , edge and eth but in android WebView i got 'too many redirect' error
By the way when I set WebView cache mode to none, this error had gone, but i need the cache mode,
Any body can help me?
Solution
Use this code to initialize webview and set url, it is work fine with me with all Android versions
@SuppressLint("SetJavaScriptEnabled")
private fun initWebView() {
webView.settings.javaScriptEnabled = true
webView.settings.loadsImagesAutomatically = true
webView.scrollBarStyle = View.SCROLLBARS_INSIDE_OVERLAY
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
}
private fun webViewListener() {
webView.webViewClient = object : WebViewClient() {
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
Log.d(TAG, url)
}
override fun onReceivedError(view: WebView, request: WebResourceRequest,
error: WebResourceError) {
super.onReceivedError(view, request, error)
//Error load url
}
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
//Loading url
view?.loadUrl(url)
return true
}
}
}
Add this line in Manifest File
<application
...
android:usesCleartextTraffic="true">
You can read more about usesCleartextTraffic
Answered By - Mahmoud Waked
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.