# Integrate your app with Firebase Dynamic Links ​ Gamiphy ~~bot~~ **Loyalty app** uses ~~a~~ firebase dynamic ~~link~~**links** for deep linking. ~~creating and reciving deeplink will be throw Firebase Dynamic links, that~~ **This** is why you must integrate Firebase in your project. ~~At first, you should integrate your Android project with Firebase~~ **Please follow the documentation to integrate with Firebase** [~~Follow~~ Firebase Docs](https://firebase.google.com/docs/android/setup) ​ # Set up Firebase Dynamic Links SDK After making sure that your app connected ~~with~~ **to** your Firebase project, open [Firebase Console](https://console.firebase.google.com/u/0/). You will find a SHA-256 key ~~must~~ **that will** be specified ~~in firebase console~~ **to use** for Dynamic Links Functionality > [It will be great if you can make the steps as bullets](/yFyDDA99QyqVVlrzg5wjzQ) Add the dependency for the Firebase Dynamic Links Android library to your module ~~(app-level)~~ *`I didn't get that`* ~~Gradle file~~`not necessary` (usually app/`build.gradle`): ```gradle dependencies { ... implementation 'com.google.firebase:firebase-dynamic-links:19.1.0' implementation 'com.google.firebase:firebase-analytics:17.2.3' } ``` ​ # Define your URL prefix `I think this should go before the previous step` ​ In the Firebase console, open the **Dynamic Links** section. If you already have a Dynamic Links domain, take note of it. You need to provide a Dynamic Links domain when you programmatically create Dynamic Links. you should save it under url_prefix in your Android Studio localization file. `You are trying to describe two scenarios here, right? If yes, then we need to make a better distinction between them.` ​ ​ # Create a Dynamic Link ~~After Integrating Firebase/ Firebase dynamic link in your android project **app** then you can use Firebase SDK in your code. you should create the dynamic link.~~ **Now you can** use the following code to create a dynamic link: ​ ```kotlin dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink() .setLink(Uri.parse(getString(R.string.my_website_uri))) .setDomainUriPrefix(getString(R.string.url_prefix)) // Open links with this app on Android .setAndroidParameters(DynamicLink.AndroidParameters.Builder().build()) // Open links with com.example.ios on iOS .setIosParameters(DynamicLink.IosParameters.Builder("com.example.ios").build()) .buildDynamicLink() val dynamicLinkUri = dynamicLink.uri ``` ​ # Receive Firebase Dynamic Links parameter `Can we use bullet points?` ​ ### Add intent filter for deep links ​ **In order to handle the dynamic links** you ~~must~~ should add a new intent filter to the activity ~~that handles deep links for your app~~. The intent filter ~~should~~ **will** catch **the** deep links, **if exist** `not sure if that is alright`. ~~of your domain since the Dynamic Link will redirect to your domain if your app is installed~~. This is required for your app to receive the dynamic l ink data after it is installed/updated from the Play Store ~~and one tap on Continue button~~ `I didn't get that one`. In `AndroidManifest.xml` ​ ```xml <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="url_prefix" android:scheme="https"/> </intent-filter> ``` ​ ### Handle deep links To receive the deep link, call the `getDynamicLink()` method: ```kotlin Firebase.dynamicLinks .getDynamicLink(intent) .addOnSuccessListener(this) { pendingDynamicLinkData -> // Get deep link from result (may be null if no link is found) var deepLink: Uri? = null if (pendingDynamicLinkData != null) { deepLink = pendingDynamicLinkData.link referral = deeplink.getQueryParameter("referralId") } } .addOnFailureListener(this) { e -> Log.w(TAG, "getDynamicLink:onFailure", e) } ``` ​ ~~We need a referral to send it with Gamiphy’s bot URL.~~ `I don't get it`. ​ # Add parameter to the bot URL ​ Add ShareUrl and ~~referralId~~ **referrerId** to Gamiphy’s ~~bot~~ **app** url as query string ​ ​ ```kotlin var builder: Uri.Builder = Uri.Builder().scheme("https") .authority(getString(R.id.gamiphy_bot_url)) .appendQueryParameter("referralId", referral) .appendQueryParameter("shareUrl", dynamicLink) var botUrl: Uri? = builder.build() ``` ​ ​ # Open ~~the bot~~ Gamiphy App ​ Insert these few lines in your onClickListener to open the ~~bot~~ app in your mobile browser. ​ ```kotlin val intent = Intent(Intent.ACTION_VIEW, botUrl) startActivity(intent) ```