Code to open browser is opening an activity

29 views Asked by At

Trying to open the browser with ACTION_VIEW intent but an activity from manifest is opened instead.

Here is my code

    val url = "https://www.google.com"
    val query = Uri.encode(url, "UTF-8")
    val browserIntent = Intent(CATEGORY_BROWSABLE, Uri.parse(Uri.decode(query)))
    browserIntent.setAction(ACTION_VIEW)
    activity.startActivity(browserIntent)
2

There are 2 answers

0
Anga On BEST ANSWER

For anyone else experiencing this.

The reason for this behaviour was I had a deeplink with domain of the url parsed. This is why an Activity in the app is started.

0
Aimar On

I think the above code will work fine but if you are facing problem then instead of decode and encode as they both will be same you can directly use like this

val bint = Intent(Intent.ACTION_VIEW, Uri.parse("https://google.com"))
startActivity(bint)

Hope it helps!!