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

标签 android kotlin android-jetpack-compose

我想将用户重定向到另一个打开 Internet 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")
}

关于android - 如何在 Compose 函数的按钮单击中启动 Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66940091/

相关文章:

android - Jetpack 组成 : how to force a dropdownmenu to be anchored underneath its parent?

android - Google pay 开发者帐户在哪里以及如何生成公钥并上传到其中?

android - 英特尔 XDK : Connecting your mobile app to a database

android - 工作经理适合这些情况吗?

while-loop - Kotlin - 将 while 循环转换为函数式样式

android - 为什么 FocusManager 在 AlertDialog 中不起作用?

java - 通过 Wifi 从 Android 应用程序向 Raspberry Pi 发送数据

android - 在Android响应式(Reactive)编程中,如何在应用过滤器后拆分流对象数据?

kotlin - TestContainers 和 Mysql : Access denied for user '' @'172.17.0.1' (using password: NO)

android - 如果不使用 Card 覆盖,Compose Lottie 组件将无法正常工作