【问题标题】:How do I start an Intent inside a Compose function's button click如何在 Compose 函数的按钮单击中启动 Intent
【发布时间】:2021-06-30 13:14:32
【问题描述】:

我想将用户重定向到另一个打开 Internet url 的活动。单击按钮时。

这是我目前的代码

Button(onClick = {
          val intent = Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"))
          // Here is some code that starts the activity
       }) {
          Text(text="APPLY HACK")
       }

【问题讨论】:

    标签: android kotlin android-jetpack-compose


    【解决方案1】:

    你可以使用类似的东西:

    val intent = Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"))
    val context = LocalContext.current
    
    Button(onClick = {
        startActivity(context, intent, null) }
    ) {
        Text("BUTTON")
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-23
      相关资源
      最近更新 更多