如何使用 android 中的深层链接打开应用程序并获取参数?

How do I use deep-linking in android to open app and fetch arguments?

所以我试图在我的应用程序中执行 deep-linking 以确认用户输入的电子邮件。到目前为止,我无法打开我的应用程序抛出 link 后端给我。

到目前为止我已经做到了。

这是我的manifest.xml

 <activity
            android:name=".ui.registration.activities.ARegistration"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustResize">

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https"
                    android:host="something.com"
                    android:path="/verify-email" />

            </intent-filter>
        </activity>

这是我的 URL 在我的电子邮件中

https://something.com/verify-email?registrationId=1111&token=12345

这是我的注册表activity

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.a_registration)
        colorStatusBar(frameRegistration, R.color.colorPrimary)

        val data = intent?.data

        val token = data?.getQueryParameter("token") //trying to obtain the token here
        Toast.makeText(applicationContext,token,Toast.LENGTH_SHORT).show()

}

有人可以帮忙吗?

您的代码工作正常。 Screen shot

但为了触发您的应用程序,在浏览器中复制并粘贴 url 不受影响。您应该使用带有 link 的 html 并点击它,或者使用 Android Studio [link]tools 菜单中的 App Links Assistant

html 托管在本地服务器上以模拟真实场景的文件:

 <!DOCTYPE html>
<html>
<body>
<a href="https://something.com/verify-email?registrationId=1111&token=12345">Lunch</h1>
</body>
</html>

应用链接助手:

<data
    android:host="something.com"
    android:pathPattern="/verify-email"
    android:scheme="https" />

粘贴这个就可以了。

或 如果这不起作用,请转到:设置 -> 应用程序 -> 您的应用程序 -> 设置为默认值。并将 "go to supported URLs" 更改为始终询问或在此应用程序中。可能是您选择了浏览器作为应用打开的默认浏览器 url link