3

My question is similar to this recent question for iOS.

Firebase Dynamic links work as expected on a device with the app already existing, but I fail to get a referral when I install the app (currently in the beta channel) from the Play Store.

Specifically, AppInviteReferral.hasReferral(getIntent()) returns false when the app is installed from the PlayStore beta channel.

According to the linked answer, Dynamic Links work most of the time, but there may be undocumented edge cases that will cause it to fail. I'll highlight what is specific to my case, so you might help me find what's missing in my setup.

  1. I only just updated my Firebase libraries to 10.2.6 from 10.2.4. There was no change to the Firebase Invites library in the changelog.

If it matters, here's the order in which I include the libraries

compile 'com.google.firebase:firebase-core:10.2.6'
compile 'com.google.firebase:firebase-messaging:10.2.6'
compile 'com.google.firebase:firebase-auth:10.2.6'
compile 'com.google.firebase:firebase-database:10.2.6'
compile 'com.google.firebase:firebase-invites:10.2.6'
  1. My SplashScreenActivity.java serves as both the launcher activity, and the activity that accepts and handles deeplinks. Here's the activity declaration in the AndroidManifest

    <activity
        android:name=".ui.setup.SplashScreenActivity"
        android:label="@string/app_name"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
    
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <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:scheme="https"
                android:host="deeplinks.myCompanyDomain.com"
                android:pathPrefix="/mobile"/>
        </intent-filter>
    </activity>
    
  2. SplashScreenActivity.java does not setContentView(int id). It just uses a theme to display the splash screen while the rest of the app's resources "load". I don't know if this matters, but I'm putting it out there.

  3. Before anything starts on the app, I check to make sure the app has the needed permissions. A continueIntoApp() method (I couldn't think of a better name) takes the user into the app when it finds it has the needed permissions, or after the user grants the app all four permissions it needs.

  4. continueIntoApp() is where all the code found on the Firebase Dynamic Links Docs is implemented. I first build and connect a GoogleApiClient.

    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
                    LogUtils.e("Deeplink connection failed");
                    LogUtils.e(connectionResult.getErrorMessage());
                    LogUtils.e(String.valueOf(connectionResult.getErrorCode()));
                }
            })
            .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(@Nullable Bundle bundle) {
                    LogUtils.d("Connected!");
                }
    
                @Override
                public void onConnectionSuspended(int i) {
                    LogUtils.e("Connection suspended!");
                }
            })
            .addApi(AppInvite.API)
            .build();
    
    googleApiClient.connect();
    

Just as an aside, the Dynamic Links docs assume the developer already knows how to setup a GoogleApiClient. I didn't. After a few frustrating days, I accidentally found the #connect() method that actually got the GoogleApiClient doing what it was supposed to do.

After this, I check if the AppInviteReferral has a referral.

    //boolean autoLaunchDeepLink = true;
    if(AppInviteReferral.hasReferral(getIntent())){
        LogUtils.d("Referral found!");
        AppInvite.AppInviteApi.getInvitation(googleApiClient, SplashScreenActivity.this, true)
                .setResultCallback(new ResultCallback<AppInviteInvitationResult>() {
                    @Override
                    public void onResult(@NonNull AppInviteInvitationResult appInviteInvitationResult) {

                        LogUtils.d("Processing appInviteInvitationResult...");

                        if(appInviteInvitationResult.getStatus().isSuccess()){
                            Intent intent = appInviteInvitationResult.getInvitationIntent();
                            String deepLink = AppInviteReferral.getDeepLink(intent);

                            LogUtils.d("Deeplink is " + deepLink);
                            AppConfig appConfig = new AppConfig(SplashScreenActivity.this);
                            appConfig.put(ModelKeys.TEMP_JOIN_BRANCH_DEEPLINK, deepLink);
                            startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
                            //parseDeeplink(deepLink);
                        }else {
                            LogUtils.d("No deeplink found!");
                            startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
                        }
                    }
                });
    }else {
        LogUtils.d("No referral found!");
        startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
    }

You will notice I have commented out autoLaunchDeepLink and, by default, pass true to AppInvite.AppInviteApi.getInvitation(). I'm still not sure when I should set this value to true or false. I also don't know how, after a fresh installation from a Dynamic Link (with autoLaunchDeepLink as false), Firebase knows how to "start the dynamic link".

That's as far as the Dynamic Links implementation goes. My problem is as stated above: when I have the app already installed, AppInviteReferral.hasReferral(getIntent()) returns true , and the code runs as normal. When the user follows the Dynamic Link to the PlayStore and downloads the beta release, AppInviteReferral.hasReferral(getIntent()) returns false, and the deeplink is not followed.

Why is this happening? What am I missing?

wsgeorge
  • 1,928
  • 17
  • 20

2 Answers2

3

I don't think you're missing anything - it does seem like the Play Store doesn't send INSTALL_REFERRER broadcasts for the Beta channel installs, and its that referrer which is used as the mechanism for passing the deeplink post-install.

It should work OK if you're using a product app, but it is a little curious that the beta installs don't support that.

Ian Barber
  • 19,765
  • 3
  • 58
  • 58
  • I'm about to implement Firebase Dynamic Links myself in my app, so I don't have a real answer to this question... I just wanted to point out that actually I'm migrating from Adjust SDK to Firebase and I tested my beta apk from the Play Store: with Adjust INSTALL_REFERRER was sent correctly even from the Beta channel. – Massimo Baldrighi Jul 03 '17 at 20:47
  • I am having the same problem, the dynamic links were detected perfectly on my DEBUG version of app but when i posted the release vesion of my app in the ALPHA channel , I am unable to receive the dynamic link in my splash screen ... If you found the solution then please do report. – Udit Kapahi Jul 11 '17 at 07:22
  • Thanks Ian. It works perfectly now. This issue was a bit weird. – wsgeorge Aug 23 '17 at 10:08
  • Hi, I know I'm a little bit late, but i have the exact same problem as my app is currently on Beta. Is there a way to manually send the INSTALL_REFERRER to test this functionality on Beta phase? – Quim Baget Nov 26 '18 at 14:41
  • @QuimBaget You can change your run/debug configuration in Android Studio to launch URL instead of Default Activity. This will help you test the use case when your app is not installed. I haven't found a solution to send INSTALL_REFERRER on Beta phase. – Nikola Samardzija Feb 02 '21 at 12:11
0

Had the same issue. Our problem was that we had two intent-filters almost similar in the AndroidManifest.xml, which caused the Google Play to lose the intent we wanted. Instead of showing "Continue" button it redirected us to uninstall/open page on the play.

Suggesting to work with https://firebase.google.com/docs/dynamic-links/android/receive