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

PendingDynamicLinkData返回null求助:邀请奖励APP动态链接异常

Hey there! I’ve run into this exact PendingDynamicLinkData null issue a few times with Firebase Dynamic Links, so let’s walk through the most common fixes step by step to get your share-to-reward feature working.

1. First, Validate Your Manifest Configuration

Most null cases start with misconfigured intent filters or activity settings. Let’s double-check:

  • Ensure your MainActivity has the correct intent filter to capture Dynamic Links:
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <!-- Replace with your Firebase Dynamic Link domain -->
            <data android:host="yourapp.page.link" android:scheme="https" />
            <!-- Optional: Add custom scheme if you're using it -->
            <data android:scheme="yourapp" android:host="invite" />
        </intent-filter>
    </activity>
    
  • Avoid using launchMode="singleInstance" or launchMode="singleTask" for MainActivity unless you explicitly handle onNewIntent (more on that below). Default standard or singleTop works best for Dynamic Link handling.

The issue often happens because you’re only checking for links in onCreate—but if the app is already running in the background, the link will trigger onNewIntent instead. Here’s the correct approach:

// Example in Kotlin; adjust for Java as needed
class MainActivity : AppCompatActivity() {
    private val TAG = "MainActivity"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Set up your share button click listener
        findViewById<Button>(R.id.btn_share_reward).setOnClickListener {
            generateAndShareInviteLink()
        }

        // Handle dynamic link on app launch
        handleDynamicLink()
    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        setIntent(intent) // Update the current intent with the new one
        handleDynamicLink() // Re-process the link
    }

    private fun generateAndShareInviteLink() {
        // Replace with your actual inviter ID logic
        val inviterId = "user_12345"
        val baseLink = Uri.parse("https://yourapp.com/invite?inviterId=$inviterId")

        // Build valid Firebase Dynamic Link
        val dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLink(baseLink)
            .setDomainUriPrefix("https://yourapp.page.link") // Match your Firebase domain
            .setAndroidParameters(DynamicLink.AndroidParameters.Builder().build())
            .buildDynamicLink()

        // Share the generated link
        val shareIntent = Intent(Intent.ACTION_SEND)
        shareIntent.type = "text/plain"
        shareIntent.putExtra(Intent.EXTRA_TEXT, "Join my app via this link: ${dynamicLink.uri}")
        startActivity(Intent.createChooser(shareIntent, "Share invite link"))
    }

    private fun handleDynamicLink() {
        FirebaseDynamicLinks.getInstance()
            .getDynamicLink(intent)
            .addOnSuccessListener { pendingDynamicLinkData ->
                if (pendingDynamicLinkData != null) {
                    val deepLink = pendingDynamicLinkData.link
                    val inviterId = deepLink?.getQueryParameter("inviterId")
                    // Now you can process the reward for this inviter ID
                    Log.d(TAG, "Received inviter ID: $inviterId")
                } else {
                    Log.w(TAG, "PendingDynamicLinkData is null—check the steps below!")
                }
            }
            .addOnFailureListener { e ->
                Log.e(TAG, "Failed to fetch dynamic link", e)
            }
    }
}
  • Confirm your Firebase console has the correct Dynamic Link domain configured (no typos!).
  • Test your generated link directly: Paste it into a mobile browser—if it doesn’t prompt to open your app (or redirect to Google Play if not installed), the link is invalid.
  • Ensure you’re using the latest Firebase Dynamic Links dependency in your build.gradle:
    implementation 'com.google.firebase:firebase-dynamic-links:21.2.0' // Use the latest version
    
4. Avoid These Common Testing Mistakes
  • Don’t manually open the app after installation: When a user clicks your link and installs the app, they must open it via the "Open" button in Google Play (or the browser’s app launch prompt). Opening manually will not pass the Dynamic Link data.
  • Use a real device, not an emulator: Emulators often have issues with intent handling for deep links.
  • Clear app data before retesting: Cached intent data can cause unexpected null results.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 10:06:02