3

I have a WebView in my app. It works properly but at Api 20, WebView does not show the content.

I checked the logs and see these errors

I/chromium: [INFO:CONSOLE(7)] "The key "shrink-to-fit" is not recognized and ignored.", source: https://...

I/chromium: [INFO:CONSOLE(43)] "Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode", source: https://... (43)

I overviewed some answers and they generally suggest to use

webView.settings.useWideViewPort = true
webView.settings.loadWithOverviewMode = true

I have already implement these settings but still same error happens. WebView shows noting

Here is my WebView Settings

/**
 * Initialize the WebView
 */
@SuppressLint("SetJavaScriptEnabled")
private fun initWebView() {

    webView.webViewClient = object : WebViewClient() {

        @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
        override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {

            return super.shouldOverrideUrlLoading(view, request)
        }

        override fun onPageStarted(
            view: WebView, url: String, favicon: Bitmap?) {
            showProgressDialog()
        }

        override fun onPageFinished(view: WebView, url: String) {
            hideProgressDialog()
        }

        @RequiresApi(api = Build.VERSION_CODES.M)
        override fun onReceivedError(view: WebView, request: WebResourceRequest, error: WebResourceError) {
            // Your code to do
            hideProgressDialog()
        }

        override fun onReceivedError(view: WebView, errorCode: Int, description: String, failingUrl: String) {
            // Handle the error
            hideProgressDialog()
        }

        override fun onReceivedSslError(view: WebView, handler: SslErrorHandler?, error: SslError) {
            // ignore ssl error
            if (handler != null) {
                handler.proceed()
            } else {
                super.onReceivedSslError(view, null, error)
            }
        }
    }

    webView.isHorizontalScrollBarEnabled = false
    webView.settings.javaScriptEnabled = true
    webView.settings.useWideViewPort = true
    webView.setInitialScale(1)
    webView.settings.loadWithOverviewMode = true
    context?.let { webView.setBackgroundColor(ContextCompat.getColor(it, R.color.colorDarkBlue)) }

    }

    /**
     * Load url
     */
    private fun loadPage(url: String) {
        webView.loadUrl(url)
    }

Someone have a idea? I will be appreciate for any help

ysfcyln
  • 2,857
  • 6
  • 34
  • 61

0 Answers0