I am trying to create an application that allows sending any website as data, but when I write the address it does not load in the second activity.
Note: in the manifest I already put this code <uses-permission android: name = "android.permission.INTERNET" />
This is my code
MainActivity
bt_ir.setOnClickListener {
val sitio = pt_sitio.text.toString()
val inten = Intent (this, MainActivity2_Webview::class.java)
inten.putExtra("Clave", sitio)
startActivity(inten)
}
Second Activity
val intent = intent
val name = intent.getStringExtra("Clave")
wv_sitio.loadUrl("http//:${name}")
bt_atras.setOnClickListener {
finish()
}
You have a typo in your URL string after http
, it should be ://
instead of //:
As well as that, if you're using http
instead of https
, you might need to set usesCleartextTraffic
in the manifest to true
- this was the default before API 28, if you target 28+ it defaults to false and you have to explicitly enable it.
There's also a more complex system with a Network security configuration if you want more fine control over which sites are allowed through.
Depending on what's going on in your WebView, you might need use setMixedContentMode to ALWAYS_ALLOW
or something - this is a security problem, so using https would be better, but that's up to you!