You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Android Activity中直接从Firebase动态链接邮件提取参数值

嘿,我懂你这种明明能打开深度链接却拿不到参数的头疼——之前我也碰到过类似的情况,给你几个实际可行的解决方案:

从深度链接中提取userId和session参数的方法

1. 直接从启动Activity的Intent解析参数

当你的深度链接Activity被唤起时,系统会把完整的URL通过Intent传递过来,你可以直接从Intent中提取并解析参数:

// 在你的深度链接Activity的onCreate方法中编写
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_deep_link);

    Intent incomingIntent = getIntent();
    if (Intent.ACTION_VIEW.equals(incomingIntent.getAction())) {
        Uri linkData = incomingIntent.getData();
        if (linkData != null) {
            // 直接获取指定参数
            String userId = linkData.getQueryParameter("userId");
            String session = linkData.getQueryParameter("session");
            
            // 验证并使用参数
            if (userId != null) {
                Log.d("DeepLinkDebug", "获取到的userId: " + userId);
            }
            if (session != null) {
                Log.d("DeepLinkDebug", "获取到的session: " + session);
            }
        }
    }
}

2. 检查Manifest中的深度链接配置是否完整

有时候参数拿不到是因为Manifest里的<intent-filter>配置有遗漏,确保你的Activity包含了短链和目标域名的匹配规则:

<activity android:name=".YourDeepLinkActivity">
    <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="ejr3J.app.goo.gl" />
        <!-- 匹配目标深度链接域名 -->
        <data
            android:scheme="https"
            android:host="www.example.com" />
    </intent-filter>
</activity>

划重点:如果你的短链跳转时没有自动传递参数,一定要先检查短链的生成配置——有些短链服务默认会丢弃原链接的参数,需要手动开启参数保留功能。

3. 排查短链跳转后的参数丢失问题

如果上述方法还是拿不到参数,先打印出Intent传递的完整URL,确认参数是否被传递过来:

Uri linkData = incomingIntent.getData();
Log.d("DeepLinkDebug", "收到的完整URL: " + linkData.toString());
  • 如果打印的是短链地址且包含参数:直接用getQueryParameter提取即可;
  • 如果打印的是目标URL但没有参数:说明短链跳转时丢失了参数,需要调整短链的生成规则;

4. 可选:使用App Links避免浏览器中转

如果你的应用配置了Android App Links,确保assetlinks.json文件配置正确,这样系统会直接把链接参数传递给应用,跳过浏览器中转环节,减少参数丢失的概率。

内容的提问来源于stack exchange,提问作者Dev b

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:47:33