android - [Android][kotlin] 如何为意图设置“方案”
问题描述
我是 Android 的初学者。
我写了以下代码:
val button_2 = findViewById<Button>(R.id.button2)
button_2.setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("https://www.google.com")
startActivity(intent)
}
<activity android:name=".ThirdActivity">
<intent-filter xmlns:tools="http://schemas.android.com/tools" tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="https"/>
</intent-filter>
</activity>
我只是想知道我是否可以用 xml 配置<data android:scheme="https">
代替类似的东西
val button_2 = findViewById<Button>(R.id.button2)
button_2.setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("https://www.google.com")
intent.scheme = "https"
startActivity(intent)
}
但是告诉我在 Intent ClassAndroid Documentation
中没有。setScheme
If there is other magic methods that i can use?
谢谢。
解决方案
您要做的是在按下按钮时打开一个链接。这是对的吗?
推荐阅读
- android - 如何通过单击小部件中的按钮来关闭覆盖?
- google-smart-home - 我在哪里可以找到我的 google home 操作的完整 URL?
- go - 无法将 Go 二进制文件上传到 Elastic Beanstalk
- html - 如何隐藏页面中的所有元素,除了最上面的祖先元素?
- python - 我可以遍历python中的逻辑运算符吗?
- python - URL中间的通配符
- python - 序列化程序删除 Django 3.1 中的一对多关系
- c++ - 如何重载 operator[] 以索引自定义向量类的 shared_ptr 元素?
- flutter - Flutter onResume 检测到音乐暂停为时已晚
- amazon-web-services - 如何使用 IAM 策略 AWS 仅向 S3 存储桶的根账户用户授予访问权限?