如何在 Compose 函数的按钮单击中启动 Intent

How do I start an Intent inside a Compose function's button click

我想将用户重定向到另一个打开互联网 url 的 activity。单击按钮。

到目前为止,这是我的代码

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")
       }

您可以使用类似的东西:

val intent = Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"))
val context = LocalContext.current

Button(onClick = {
    startActivity(context, intent, null) }
) {
    Text("BUTTON")
}