How to link to a https url

Hello,

I am new in Kotlin. With Android Studio I am trying to create a small apk with buttons or textview to link to a https. First I did it with WebView which works properly, the problem is that I can’t see pop up messages. So I am trying to open the links with a browser, but the url change to http instead https

In MainActivity.kt

val btnViajes = findViewById<Button>(R.id.viajes)
    btnViajes?.setOnClickListener() {
       val activityWebViajes = Intent(this,webViajes::class.java)
        startActivity(activityWebViajes)       

    }

In other activity.kt

 override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_web_viajes)

    background = findViewById<LinearLayout>(R.id.back) as LinearLayout
    mWebView = findViewById(R.id.webView)
    mWebView.loadUrl(""https://****/***";")

    val webSetting = mWebView.settings

    webSetting.javaScriptEnabled = true
    mWebView.webViewClient = WebViewClient()

} 

Also I have tried, searching google, in MainActivity.kt this:

    val btnViajes = findViewById<Button>(R.id.viajes)
    btnViajes?.setOnClickListener() {
     

       var url = "https://****/***";
        startActivity(Intent(Intent.ACTION_VIEW).apply {
            data = Uri.parse(url)
        })

    }

The problem is the same it opens a browser with a link without https. I would like to know how to open https url in a browser.

Hello, this is more of an Android question than a Kotlin one. Anyway what you did should work.
I don’t know if will make any diference but try to pass the URI in the Intent constructor (I do it this way in some of my apps and I know it works):

startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))

Hi Eliote,

I still have the same issue, don’t understand why.

val btnViajes = findViewById<Button>(R.id.viajes)
    btnViajes?.setOnClickListener() {
    

       var url = "https://***/***";
        startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))

    }

The problem is in the server of the URL, and has nothing to do with the code. Try to open it directly in a browser and you will see.

1 Like

I have found the issue. I had to put another slash at the end. https://// instead https:/// without that it didn’t work.