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

Android端Facebook Deep Link始终返回null问题求助

Facebook 延迟深度链接返回null问题排查与解决

问题描述

已严格按照Facebook官方文档配置Android项目,包括添加依赖、配置Manifest文件、在MainActivity中调用AppLinkData.fetchDeferredAppLinkData方法。使用Facebook应用广告助手发送深度链接(com.moddev.gametopmoney://123),点击通知打开应用后,控制台打印返回结果为null。尝试创建新的Facebook应用后问题仍存在,无法定位原因。

项目配置详情

依赖配置

dependencies {
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.3.1'
    implementation "androidx.compose.ui:ui:$compose_ui_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
    implementation 'androidx.compose.material:material:1.1.1'
    implementation "androidx.navigation:navigation-compose:2.5.3"
    implementation "androidx.compose.runtime:runtime-livedata:$compose_version"

    implementation 'com.facebook.android:facebook-android-sdk:13.0.0'
}

Manifest配置

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET"/>
    
    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.GameTopMoney"
        tools:targetApi="31">

        <meta-data android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id"/>

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:theme="@style/Theme.GameTopMoney">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <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="posture"/>
            </intent-filter>

            <meta-data
                android:name="android.app.lib_name"
                android:value="" />
        </activity>
    </application>
</manifest>

Facebook App ID

<string name="facebook_app_id">820734572369738</string>

MainActivity代码

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val gameViewModel: GameViewModel by viewModels<GameViewModel>()

        FacebookSdk.setIsDebugEnabled(true);
        FacebookSdk.addLoggingBehavior(LoggingBehavior.APP_EVENTS);

        setAutoInitEnabled(true)
        fullyInitialize()
        AppLinkData.fetchDeferredAppLinkData(
            this
        ) {
            println("Deeplink  >>>>------->>>>  " + it)
        }
    }
}

控制台输出

2022-11-27 12:16:16.257 7697-7736/com.moddev.gametopmoney D/com.facebook.FacebookSdk: getGraphApiVersion: v13.0
2022-11-27 12:16:16.258 7697-7736/com.moddev.gametopmoney I/System.out: Deeplink  >>>>------->>>>  null
2022-11-27 12:16:16.482 7697-7736/com.moddev.gametopmoney D/com.facebook.FacebookSdk: getGraphApiVersion: v13.0

排查与解决方案

  1. 修复Intent Filter匹配问题
    你发送的深度链接scheme是com.moddev.gametopmoney,但Manifest中配置的是posture,完全不匹配。修改Intent Filter中的scheme:

    <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="com.moddev.gametopmoney"/>
    </intent-filter>
    
  2. 明确延迟深度链接的触发条件
    fetchDeferredAppLinkData仅用于获取延迟深度链接:即用户未安装应用时点击链接,跳转到应用商店安装后首次打开应用才会返回数据。如果应用已安装,直接点击链接需通过getIntent()获取数据,而非此方法。测试时需先卸载应用,再通过广告助手发送链接完成安装流程。

  3. 验证Facebook后台配置

    • 确认Facebook开发者后台中,Android平台的包名、主类名与项目完全一致,且已添加正确的密钥哈希。
    • 检查产品 > 深度链接模块是否启用,且配置的链接规则与测试链接匹配。
  4. 调整SDK初始化与调用顺序
    确保fetchDeferredAppLinkData在SDK完全初始化后执行,可改用初始化回调触发:

    FacebookSdk.initialize(this) {
        AppLinkData.fetchDeferredAppLinkData(this) { data ->
            println("Deeplink  >>>>------->>>>  " + data)
        }
    }
    
  5. 用adb命令验证普通深度链接
    执行以下命令测试链接是否能被正确识别:

    adb shell am start -a android.intent.action.VIEW -d "com.moddev.gametopmoney://123" com.moddev.gametopmoney
    

    若应用正常打开,可在onCreate中通过intent.data获取链接数据,确认基础深度链接功能是否正常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 00:50:24