Building Firebase Dynamic Links with the Android Builder API

Building Firebase Dynamic Links with the Android Builder API

I may have almost forgotten about my promise in my first Dynamic Links post

I never did

Until I started working with Dynamic Links again for one of my own upcoming apps where I’m using email-invites as a way for people to collaborate on a single shopping list. If you know Dynamic Links, you know the drill. Link brings user to the app, link carries data with it, if user doesn’t have app, user is taken to Play Store for installation and link’s data is retained through the installation process.

Now if you’re using Dynamic Links to pass data to other users like I am, you know the Firebase Console builder isn’t going to cut it. Data is dynamic (or your app is garbage), and we need more flexibility.

In comes the Android Builder API for Dynamic Links where everything is set up in app. You can build your dynamic link in your app and pass it to an intent that prepares an email.

Add the Dependencies

If you haven’t already, add this to your app-level  build.gradle file.

Build the Dynamic Link

Here’s a simple function I made to build the dynamic link I need. The data I’m passing along is contained in the link (listid). Of course, I’m using my own website to be the middle man between Firebase and my app. The DomainUriPrefix is taken from the Firebase Console when I set up Dynamic Links there. If you haven’t done that, head there now.

Assigning the Opened Activity

This is all done in the Android Manifest. This whole intent filter is what shouts out to the dynamic link when it is opened.

Receiving the Dynamic Link

In your chosen activity, you can steal the dynamic link from the intent that started the activity. After getting the dynamic link from the result, it’s all a matter of parsing the given URI to extract your data.

And that’s it

The Builder API is actually ridiculously simple. Somehow, the official docs still manages to split this whole process into 2 full pages. Sure there are a few things that I left out like buildShortDynamicLink and Analytics but come on.

If you guys in the Firebase team are reading this, how about bringing your boy in to handle the docs *wink wink nudge nudge*.

In any case, I don’t know how long it’s going to be til I get on with the other methods of creating Dynamic Links, if I even write about them at all. Here’s the thing. If you want it, or anything else for that matter, let me know in the comments.