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

Airship deep link通知启动应用时intent.getData返回null如何解决

解决方案

按下面步骤依次排查修改即可:

  • 第一步:修正AndroidManifest.xml的intent-filter配置
    给需要接收deep link的Activity添加匹配你的URL规则的intent-filter,示例如下:
    <activity 
        android:name=".YourTargetActivity"
        android:exported="true">
        <intent-filter android:autoVerify="true">
            <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="my.url"
                android:pathPrefix="/*" />
        </intent-filter>
    </activity>
    
    如果需要主Activity接收deep link就把这段intent-filter加到主Activity的声明中,Android 12及以上版本必须添加android:autoVerify="true",同时在你的域名根目录下部署正确的assetlinks.json验证文件。
  • 第二步:修正airshipconfig.properties的白名单配置
    你当前配置中的urlAllowListScopeOpenUrl = *, https://my.url里的通配符*会导致Airship默认走内部跳转逻辑,不会触发系统隐式intent,修改为如下配置:
    urlAllowListScopeOpenUrl = https://my.url
    urlAllowList = https://my.url
    # 不需要JavaScript相关能力的话可以删除下面这行配置
    urlAllowListScopeJavaScriptInterface = https://my.url
    
  • 第三步:检查启动模式和intent数据获取逻辑
    如果你给接收deep link的Activity设置了singleTask/singleInstance启动模式,需要重写onNewIntent方法主动更新intent数据:
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        // 这里可以同步调用intent.getData()获取deep link数据
    }
    

完成以上配置后,移除你之前设置的自定义DeepLinkListener,Airship就会自动把白名单内的deep link以ACTION_VIEW隐式intent的形式发送给系统,匹配到你配置的Activity后就能正常通过intent.getData()拿到URL数据。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 19:45:04