Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

649
Visualizações
Android Kotlin open Link with button

i try to open an link with a button in Kotlin, but if i use this code

fun openNewTabWindow(urls: String, context: Context) { 
    val uris = Uri.parse(urls) 
    val intents = Intent(Intent.ACTION_VIEW, uris) 
    val b = Bundle() 
    b.putBoolean("new_window", true) 
    intents.putExtras(b)
    context.startActivity(intents)
}

And in my button i use

openNewTabWindows("https://Google.com/")

It say it need context After url?

What does that mean?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

openNewTabWindow(urls: String, context: Context) function needs 2 paramters, a String and a Context.

And in my button i use openNewTabWindows("https://Google.com/")

You just called this function with 1 parameter, then of course

It say it need context After url.

You need to pass a Context as the second parameter. Since you say you are implementing the action of clicking a button (which is, inside @Override public void onClick(View v) {} in Java, or a Lambda with type (View) -> Unit in Kotlin), which is probably inside an Activity, and the reference of this may be changed, you can pass getContext() or for example MainActivity.this as the context needed for program, or

openNewTabWindows("https://Google.com/", context) // Kotlin version of getContext()
openNewTabWindows("https://Google.com/", this@MainActivity) // Kotlin version of MainActivity.this

May both OK.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda