SARRAN N
SARRAN N

Reputation: 196

Webview not loading url in android

I have this code.

@SuppressLint("SetJavaScriptEnabled")
@Composable
fun WebPageScreen(urlToRender: String) {
  AndroidView(factory = {
    WebView(it).apply {
      layoutParams = ViewGroup.LayoutParams(
          ViewGroup.LayoutParams.MATCH_PARENT,
          ViewGroup.LayoutParams.MATCH_PARENT
      )
      webViewClient = WebViewClient()
      loadUrl("https:....") //Url to be loaded
    }
  }, update = {
    it.loadUrl("https:...") //Url to be loaded
  })
}

Im trying to loading this url

When i load this page it is redirecting but showing error what is the problem and how to solve this? this is how it shows inside app

Upvotes: 1

Views: 2327

Answers (2)

SARRAN N
SARRAN N

Reputation: 196

The webview is not working for particular url because the authorizer of that website have secured it in such a way. To Access that url in webview we need to get client certificate from the authority.

Upvotes: 0

Jalalkun
Jalalkun

Reputation: 181

Create this file

res/xml/network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">URL</domain>
    </domain-config>
</network-security-config>

add this line in manifest, inside application

android:networkSecurityConfig="@xml/network_security_config"

or

you can use this line in manifest

android:usesCleartextTraffic="true"

if your website is not using SSL yet, you can use certbot for free SSL

Upvotes: 1

Related Questions