Best android app development with firebase dyanmic link

How to Create a Firebase Dynamic Link in Android

Dynamic Links are the links whose behavior you can decide. Firebase Dynamic Links can behave differently or similarly on multiple platforms – Android, IOS, and Web platforms based on what you need.

Firebase Dynamic links are created to provide the best experience to your app users. You can create dynamic links in different ways. You can use Firebase Console, IOS or Android Builder API, and Rest API.

When a user opens a Firebase dynamic link in an Android or IOS device they are taken directly to the linked content in your native app. For users who don’t have your app installed, you can send them to your website.

  1. Create a project with an empty activity.
  2. Set the Project name, package name, and minimum SDK version.
  3. Create a Firebase project and add a JSON file to your project.
  4. Add dependency in build.gradle
    implementation 'com.google.firebase:firebase-dynamic-links:21.1.0' // Use the latest version
    implementation 'com.google.firebase:firebase-core:20.0.0' // Use the latest version
  5. Initialize the Firebase App in your onCreate()
    FirebaseApp.initializeApp(this);
  6. Generate Dynamic Link
    import com.google.firebase.dynamiclinks.DynamicLink;
    import com.google.firebase.dynamiclinks.FirebaseDynamicLinks;
    import com.google.firebase.dynamiclinks.ShortDynamicLink;
    // Create the Dynamic Link
    DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
    .setLink(Uri.parse("https://www.example.com/"))
    .setDomainUriPrefix("https://your-subdomain.page.link")
    .setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
    .buildDynamicLink();
    // Get the generated Short Link
    dynamicLink.getShortLink()
    .addOnSuccessListener(this, shortLink -> {
    // Handle the short link, e.g., share it with users
    String shortUrl = shortLink.toString();
    // TODO: Share or use the short link
    })
    .addOnFailureListener(this, e -> {
    // Handle errors
    });
  7. Handle Dynamic Link Clicks
    //Manifest file
    <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="your-subdomain.page.link"
    android:scheme="https" />
    </intent-filter>
    //onCreate()
    FirebaseDynamicLinks.getInstance()
    .getDynamicLink(getIntent())
    .addOnSuccessListener(this, pendingDynamicLinkData ->{ 
    if (pendingDynamicLinkData != null) {
     Uri deepLink = pendingDynamicLinkData.getLink();
    // Handle the deep link as needed
    }
    })
    .addOnFailureListener(this, e -> {
    // Handle errors
    });

For more Android development services reach out to Sreyas IT Solutions. Sreyas is also a leading service provider of web and e-commerce application development, website designing, data migration, database management, and many more.

Recent Blogs


Posted

in

,

by

Tags:

To Know Us Better

Browse through our work.

Explore The Technology Used

Learn about the cutting-edge technology and techniques we use to create innovative software solutions.