gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 23:37:51 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com