2

I am sending an authentication link to the user's email address using Android and Firebase. Everything works as expected with Android 9, 10, and 11, with both release and debug versions. However, when tapping on the authentication link on devices running Android 12, the browsers (I tried with several browsers) redirect to an error page "Invalid Dynamic Link, requested URL must be a parsable and complete DynamicLink, etc...", whereas the same link works on other devices. What am I missing?

Here's the code:

ActionCodeSettings actionCodeSettings =
            ActionCodeSettings.newBuilder()
                    .setUrl("https://appName.page.link")
                    .setHandleCodeInApp(true)
                    .setIOSBundleId("com.appName.ios")
                    .setAndroidPackageName(
                            "com.appName.android",
                            false, 
                            getResources().getString(R.string.min_version_android))
                    .build();

   
    FirebaseAuth auth = FirebaseAuth.getInstance();
    auth.sendSignInLinkToEmail(emailAddress, actionCodeSettings).addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void unused) {
            Intent intent = new Intent(SignIn.this, CheckSignInInbox.class);
            startActivity(intent);
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            String msg = getTimestamp() + "Error in sendSignInLinkToEmail: " + e.getMessage();
            logErrorAndFirebaseCrash(SignIn.this, msg);
        }
    });
nibbana
  • 698
  • 1
  • 8
  • 21

2 Answers2

3

I found the cause of the issue. In the manifest, in order to make it work with Android 12 as well, I had to include in my intent-filter android:autoVerify="true", as follows:

<intent-filter android:autoVerify="true">
     <action android:name="android.intent.action.VIEW" />

     <data
         android:host="domainname.page.link"
         android:scheme="https" />

         <category android:name="android.intent.category.BROWSABLE" />
         <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
nibbana
  • 698
  • 1
  • 8
  • 21
  • Saved my day! Had an older app (flutter v1.22) with Firebase passwordless sign-in that I needed to port to Android 12 and I just couldn't get the link to be opened in the app (instead in Play Store via the browser); this was the cause. Thanks! – ezmegy Nov 10 '22 at 12:17
  • Glad to hear it. Don't hesitate to accept the answer then, tks – nibbana Dec 01 '22 at 16:18
  • In case someone is facing this issue and cannot find the issue, in my case, the change is that before in the "intent-filter" the "android:scheme" part was at the beginning, not it has to be at the end. So from this: ``` ``` To this: ``` ´´´ Hope it saves someone an entire day ;) – Fernando Luca De Tena Mar 29 '23 at 18:28
  • I have problem now with api 13. When click link on Android 13 device that won't open app. It works for other versions. I can't solve this. – Ahmet Yılmaz Apr 28 '23 at 07:18
  • @AhmetYılmaz have you got solution for api 13? – Himani Jul 03 '23 at 08:55
  • 1
    @Himani Changed target sdk to 32 that solved for me. – Ahmet Yılmaz Jul 03 '23 at 09:27
  • 1
    @Himani Add all sub domains host (long and short dynamic link) in the data tag in your intent filter declared in `AndroidManifest.xml` – Fcps Jul 10 '23 at 14:26
0

If you target sdk 33 and still have the problem, check on firebase console your dynamic link details. You'll see there are different host for long and short dynamic link. Add both in your <data> in your <intent-filter> in your AndroidManifest.xml. It worked for me to add all sub domains in data tag.

Fcps
  • 335
  • 4
  • 19