Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link button with website in android studio using kotlin

I want to link button in my application with a website as when user click on this button the website open in browser or in application ,, I using kotlin not java ,, How can i make it ? :) i try to use this code :

bu1.setOnClickListener({
var gourl= Intent(this,Uri.parse("https://www.facebook.com/"))
startActivity(gourl)
})


 bu1.setOnClickListener({
var gourl= Intent(this,Uri.parse("https://www.facebook.com/"))
startActivity(gourl)
})

 bu1.setOnClickListener({
var gourl= Intent(this,Uri.parse("https://www.facebook.com/"))
startActivity(gourl)
})
like image 463
A.Essam Avatar asked Aug 06 '17 18:08

A.Essam


1 Answers

Do like this:

    val url = "http://www.example.com"
    val i = Intent(Intent.ACTION_VIEW)
    i.data = Uri.parse(url)
    startActivity(i)

Or like this:

    val i = Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"))
    startActivity(i)
like image 86
Bob Avatar answered Oct 13 '22 00:10

Bob