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

Firebase Android邮箱链接认证:intent-filter无法正常工作

Hey there! Let's figure out why your Firebase email link authentication is always landing on your launcher Activity instead of handling the verification flow. Since your Dynamic Links are working fine, the issue is likely tied to how your intent filters are set up or how you're handling the incoming intent in your target Activity. Here are the key fixes to check:


1. Adjust Intent Filter Priorities

If your launcher Activity has a VIEW action intent filter alongside your authentication Activity, Android will pick the one with the highest priority first. Make sure your email verification Activity has a higher priority than the launcher:

<!-- In your verification Activity's manifest entry -->
<intent-filter android:priority="100">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- Add your data matching rules here -->
    <data android:scheme="your-app-custom-scheme" />
    <!-- Or if using Dynamic Links for email auth: -->
    <data android:host="your-dynamic-link-domain.page.link" 
          android:pathPrefix="/verify-email" />
</intent-filter>

Your launcher Activity should only keep the main/launcher intent filter—no VIEW action here:

<!-- Launcher Activity's intent filter -->
<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

2. Ensure Precise Data Matching in Intent Filters

Firebase email links (whether using a custom scheme or Dynamic Links) need a specific intent filter to trigger the right Activity. If your filter is too broad, it might collide with Dynamic Links or the launcher. For example:

  • If using a custom scheme (e.g., myapp://verify-email), your filter should explicitly match that scheme.
  • If using Dynamic Links for email auth, add a pathPrefix to target only verification links (like /verify-email) so it doesn't overlap with other Dynamic Links your app handles.

3. Properly Handle the Intent in Your Verification Activity

Even if the intent filter is correct, you need to process the incoming link in your Activity. Add this logic in onCreate (or onNewIntent for singleTop/singleTask launch modes):

// Kotlin example
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_verify_email)

    val incomingIntent = intent
    val emailLink = incomingIntent.data?.toString()
    
    // Verify this is a Firebase email sign-in link
    if (emailLink != null && FirebaseAuth.getInstance().isSignInWithEmailLink(emailLink)) {
        // Retrieve the email you stored when sending the verification link
        val pendingEmail = getSharedPreferences("AppPrefs", MODE_PRIVATE)
            .getString("pending_auth_email", "")
        
        if (pendingEmail.isNotEmpty()) {
            FirebaseAuth.getInstance().signInWithEmailLink(pendingEmail, emailLink)
                .addOnCompleteListener { task ->
                    if (task.isSuccessful) {
                        // Success: update UI, navigate to home, etc.
                        Toast.makeText(this, "Email verified successfully!", Toast.LENGTH_SHORT).show()
                    } else {
                        // Handle errors: invalid link, expired link, etc.
                        Toast.makeText(this, "Verification failed: ${task.exception?.message}", Toast.LENGTH_SHORT).show()
                    }
                }
        }
    }
}

Note: Make sure you store the user's email in shared preferences (or another secure place) when you send the verification link—you'll need it to complete the sign-in.

4. Check Launch Mode Settings

If your verification Activity uses singleInstance or singleTask launch mode incorrectly, it might not receive the intent properly. Stick with standard or singleTop unless you have a specific reason to use others, and test if that resolves the redirect issue.


Start with the intent filter priority and data matching first—those are the most common culprits when links redirect to the wrong Activity. Once those are sorted, confirm your Activity is handling the intent correctly, and you should be all set!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 11:06:25