Не работает javascript в Webview
На Android 6.0 не работает javascript, на версиях выше 6-й все работает отлично, и на 5.1 тоже работает нормально.
webView.settings.cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK
try {
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null)
window.setFlags(
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
)
} catch (e: Exception) {
}
webView.settings.javaScriptEnabled = true
webView.settings.domStorageEnabled = true
webView.settings.javaScriptCanOpenWindowsAutomatically = true
webView.settings.loadWithOverviewMode = true
webView.settings.useWideViewPort = true
webView.settings.defaultTextEncodingName = "utf-8";
webView.settings.builtInZoomControls = true
webView.settings.displayZoomControls = false
webView.webChromeClient = WebChromeClient()
webView.webViewClient = object : WebViewClient() {
override fun onReceivedHttpError(
view: WebView?,
request: WebResourceRequest?,
errorResponse: WebResourceResponse?
) {
super.onReceivedHttpError(view, request, errorResponse)
}
override fun onReceivedError(
view: WebView?,
request: WebResourceRequest?,
error: WebResourceError?
) {
super.onReceivedError(view, request, error)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
} else {
}
}
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
view.visibility = View.INVISIBLE
progressBar.visibility = View.VISIBLE
}
override fun onPageFinished(view: WebView, url: String) {
super.onPageFinished(view, url)
view.visibility = View.VISIBLE
progressBar.visibility = View.INVISIBLE
}
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
if (URLUtil.isNetworkUrl(url)) {
return false
}
if (url!!.startsWith("tel:")) {
try {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(url)
startActivity(intent)
} catch (e: Exception) {
Toast.makeText(
this@ShopActivity,
getString(R.string.not_found_app),
Toast.LENGTH_SHORT
).show()
}
return true
} else {
if (url.startsWith("whatsapp:") || url.startsWith("mailto:")) {
try {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(url)
startActivity(intent)
} catch (e: ActivityNotFoundException) {
Toast.makeText(
this@ShopActivity,
getString(R.string.not_found_app),
Toast.LENGTH_SHORT
).show()
}
}
}
return true
}
}
webView.loadUrl(url)
}
override fun applyOverrideConfiguration(overrideConfiguration: Configuration) {
if (Build.VERSION.SDK_INT in 21..24) {
overrideConfiguration.uiMode =
overrideConfiguration.uiMode and Configuration.UI_MODE_NIGHT_MASK.inv()
}
super.applyOverrideConfiguration(overrideConfiguration)
}