Android — Recognize FDL before onSuccessListener

Deepak Goyal
3 min readMar 3, 2021

Sometimes we want to know if our App is opened because of Firebase Dynamic Link or not. To get the data from the FDL (Firebase dynamic link) we have to call FirebaseDynamicLinks.getDynamicLink() in the Android app.

FirebaseDynamicLinks.getDynamicLink() returns a Task and the data from FDL is returned by this task in onSuccessListener.

Before executing this task, we may want to know if the Intent has Firebase dynamic link or not.

This question is already asked on StackOverflow https://stackoverflow.com/questions/47862624/how-to-recognize-firebase-dynamic-link-before-addsucceslistener

According to the Answer in SO, we can check for particular Intent Extra. If that Intent extra is available in Intent then that means the Intent has FDL.

getIntent().hasExtra("com.google.firebase.dynamiclinks.DYNAMIC_LINK_DATA")

I used the same solution in my app and it works fine. But…

What if the Intent doesn’t contain the extra "com.google.firebase.dynamiclinks.DYNAMIC_LINK_DATA" but the app has FDL in the Intent. This case happened in my app.

In my app, I was handling the FDL as an App link. Because of the App link, FDL is directly being sent to the app instead of to the browser. In this case, Intent will not have the above extra.

So I tried another approach which is explained below.

To read more about the App link and how to set up in the Android app, check out my article https://deepakdroid.medium.com/android-deep-link-and-app-link-c07a671d498b

  • Firstly, I created a new file named “fdl_domains.xml” under the values folder.
  • Then added all the domains of Firebase dynamic links in that file as a string resource.
  • Also created a string-array to get all the FDL domains that are supported by the app.
separate file for FDL domains
  • Now use the reference of dynamic links from this file in the Android manifest.
use string resource for FDL domain in manifest

From the Intent, we can get the data that is associated with the Intent on which the current Intent is operating.

https://developer.android.com/reference/android/content/Intent#getData()

If the app is opened because of FDL then Intent.getData() will return the FDL. Then we can easily check if the app is opened due to FDL or not.

But the app can be opened due to another custom scheme or URLs. So Intent.getData() will return that URLs or custom scheme.

We have to write a code to check if the Intent.getData() is our FDL or not.

function to check if the Intent data is FDL

Now we can check if the Intent has FDL or not

This way we don’t have to check for Intent Extra. The Utility function will do the job.

getIntent().hasExtra("com.google.firebase.dynamiclinks.DYNAMIC_LINK_DATA")

This is the approach I used in my app. What do you think about that? Let me know your thoughts or suggestions.

--

--

Deepak Goyal

I’m a Software Engineer. I love programming. #java #android #kotlin #dart #flutter #firebase