Firebase

How to integrate Firebase Dynamic Links in an Android app?

Discover the secrets to adding Firebase Dynamic Links to your Android app with our easy-to-follow guide. Boost user experience and manage deep linking effortlessly.

Developer profile skeleton
a developer thinking

Overview

Incorporating Firebase Dynamic Links in an Android app lets you craft deep links that persist through the app install process and direct users to particular content within your app. This requires configuring Firebase in your project, creating Dynamic Links, and managing them in your app. You'll have to tweak your AndroidManifest.xml and utilize the Firebase SDK to identify and handle these links. This setup unlocks functionalities like one-click installations and custom user experiences, providing a strong solution for keeping users engaged and retaining them.

Get a Free No-Code Consultation
Meet with Will, CEO at Bootstrapped to get a Free No-Code Consultation
Book a Call
Will Hawkins
CEO at Bootstrapped

How to integrate Firebase Dynamic Links in an Android app?

Step 1: Set Up Firebase in the Android Project

  1. Head over to the Firebase Console and either start a new project or pick one you already have.
  2. In your Firebase project, hit the "Add app" button and select Android.
  3. Register your app with the correct package name.
  4. Download the google-services.json file and drop it into the app/ directory of your Android project.
  5. Add the Firebase SDK to your project by including these lines in your build.gradle files:

Project-level build.gradle:

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.3.10'
    }
}

App-level build.gradle:

apply plugin: 'com.google.gms.google-services'

dependencies {
    implementation platform('com.google.firebase:firebase-bom:30.0.1')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-dynamic-links'
}

Step 2: Create Dynamic Links in Firebase Console

  1. In the Firebase Console, find the "Dynamic Links" section on the left menu.
  2. Click the "Get Started" button if you haven’t already enabled Dynamic Links in your project.
  3. Click "New Dynamic Link".
  4. Set up the domain for the Dynamic Link. This might involve setting up custom subdomains in the Firebase Console.
  5. Follow the steps to configure your Dynamic Link, including the base URL, the link behavior for both iOS and Android, and any additional parameters.

Step 3: Handle Incoming Dynamic Links in Your App

  1. Open the AndroidManifest.xml file and add an intent filter to make sure your app can receive the Dynamic Link:
<activity
    android:name=".YourMainActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data
            android:host="example.page.link"
            android:scheme="https"/>
    </intent-filter>
</activity>
  1. In your main activity or the activity you want to handle the Dynamic Link, add this code to process the incoming link:
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.dynamiclinks.FirebaseDynamicLinks;
import com.google.firebase.dynamiclinks.PendingDynamicLinkData;

public class YourMainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        FirebaseDynamicLinks.getInstance()
            .getDynamicLink(getIntent())
            .addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
                @Override
                public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
                    Uri deepLink = null;
                    if (pendingDynamicLinkData != null) {
                        deepLink = pendingDynamicLinkData.getLink();
                    }

                    if (deepLink != null) {
                        // Handle the deep link. For example, open the linked content,
                        // or apply promotional credit to the user's account.
                        // ...
                    }
                }
            })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    // Handle the error
                }
            });
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        // You might want to re-call FirebaseDynamicLinks.getDynamicLink here if necessary
    }
}

Step 4: Generate Dynamic Links Programmatically

  1. To create dynamic links programmatically within your app, use the Firebase Dynamic Links Builder API.
  2. Add this code where appropriate in your app:
import com.google.firebase.dynamiclinks.DynamicLink;
import com.google.firebase.dynamiclinks.FirebaseDynamicLinks;

public void createDynamicLink() {
    String link = "https://www.example.com/?d=1234";
    String domainUriPrefix = "https://example.page.link";

    DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
        .setLink(Uri.parse(link))
        .setDomainUriPrefix(domainUriPrefix)
        .setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
        .buildDynamicLink();

    Uri dynamicLinkUri = dynamicLink.getUri();

    // Use the dynamicLinkUri, send it to others, etc.
}

This method gives you the flexibility to generate and share dynamic links directly from your app’s codebase.

Explore more Firebase tutorials

Complete Guide to Firebase: Tutorials, Tips, and Best Practices

Explore our Firebase tutorials directory - an essential resource for learning how to create, deploy and manage robust server-side applications with ease and efficiency.

Why are companies choosing Bootstrapped?

40-60%

Faster with no-code

Nocode tools allow us to develop and deploy your new application 40-60% faster than regular app development methods.

90 days

From idea to MVP

Save time, money, and energy with an optimized hiring process. Access a pool of experts who are sourced, vetted, and matched to meet your precise requirements.

1 283 apps

built by our developers

With the Bootstrapped platform, managing projects and developers has never been easier.

hero graphic

Our capabilities

Bootstrapped offers a comprehensive suite of capabilities tailored for startups. Our expertise spans web and mobile app development, utilizing the latest technologies to ensure high performance and scalability. The team excels in creating intuitive user interfaces and seamless user experiences. We employ agile methodologies for flexible and efficient project management, ensuring timely delivery and adaptability to changing requirements. Additionally, Bootstrapped provides continuous support and maintenance, helping startups grow and evolve their digital products. Our services are designed to be affordable and high-quality, making them an ideal partner for new ventures.

Engineered for you

1

Fast Development: Bootstrapped specializes in helping startup founders build web and mobile apps quickly, ensuring a fast go-to-market strategy.

2

Tailored Solutions: The company offers customized app development, adapting to specific business needs and goals, which ensures your app stands out in the competitive market.

3

Expert Team: With a team of experienced developers and designers, Bootstrapped ensures high-quality, reliable, and scalable app solutions.

4

Affordable Pricing: Ideal for startups, Bootstrapped offers cost-effective development services without compromising on quality.

5

Supportive Partnership: Beyond development, Bootstrapped provides ongoing support and consultation, fostering long-term success for your startup.

6

Agile Methodology: Utilizing agile development practices, Bootstrapped ensures flexibility, iterative progress, and swift adaptation to changes, enhancing project success.

Yes, if you can dream it, we can build it.