首页 > 解决方案 > [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?

谢谢。

标签: androidkotlin

解决方案


您要做的是在按下按钮时打开一个链接。这是对的吗?


推荐阅读