android-branch-deep-linking-attribution: Launching deeplink from within the app returns empty referral parameters

  1. Create a valid deep-link URL
  2. Launch the URL from within the app:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(deepLinkUrl));
startActivity(intent);
  1. When BranchReferralInitListener.onInitFinished(JSONObject referringParams, BranchError error) gets called when calling Branch.getInstance().initSession(), referringParams is empty.

I have modified the Branchster sample app to demonstrate this in the following branch: https://github.com/carloshwa/Branch-Example-Deep-Linking-Branchster-Android/tree/launch_deep_link_from_app

Here is my change to the sample app to launch a deep-link from the app (tap your monster to launch a deep-link to my monster): https://github.com/carloshwa/Branch-Example-Deep-Linking-Branchster-Android/commit/e06738f2598239b417fad0f2aa041e1aceb37c86 You can see branchUniversalObject in SplashActivity is null when the app is launched.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 35 (14 by maintainers)

Most upvoted comments

I’m still facing this issue on v4.2.0 unfortunately. Tried everything on this thread. Funny thing is, this wasn’t an issue when my Branchl library was version ~2.0. Back then warm start launches were handled fine, but now only cold start launches work.

Hey @aaustin, in our app, we have a SplashActivity (here we handle the deeplinks) which leads to a HomeScreen and finishes itself.

With that premise, we cannot set our SplashActivity launchMode to singleTask because every time we launch the app (even if it’s already in background) it will launch from the scratch losing the state.

Anyways, we tried to follow your directions and still doesn’t work. When onNewIntent is called we initSession but referringParams is still empty.

intent.putExtra("branch_force_new_session",true); doesn’t work for us either, as we’re not opening the link from within the app, but from a push notification.

So, just to clarify our issue:

  1. We have the app in background
  2. We receive a push notification with a deeplink
  3. We tap the notification body
  4. The SplashActivity is launched but referringParams is empty when we initSession

If the app is not in memory or It’s in background, referringParams contains the expected parameters so we can process the deeplink successfully

I got this working on 3.2.0 version and this implementation:

override fun loadAsyncDeepLink(activity: Activity): Maybe<String> {
        val intent = activity.intent
        val data = intent.data

        // WORKAROUND: When the user clicks in a BranchIO deeplink from within the app the default implementation fails to handle the
        // deeplink opening because a session is already active/open.
        // So we force the session to be open again with the parameters bellow. We need both of them!
        // This has a side effect, the callback will be called twice, the first time without the data, the second time with the deeplink data.
        intent.putExtra(Defines.Jsonkey.AndroidPushNotificationKey.key, data)
        intent.putExtra(Defines.Jsonkey.ForceNewBranchSession.key, true)
        activity.intent = intent
        return Maybe.create { emitter ->
            var count = 0
            val maxCount = if (data?.authority != branchAuthority) 1 else 2

            branch.initSession({ referringParams, error ->
                if (!emitter.isDisposed) {
                    ++count
                    if (error != null) {
                        emitter.onError(BranchException(error))
                    } else {
                        val str = referringParams.optString(DEEPLINK_URL, null)
                        if (!str.isNullOrBlank()) {
                            emitter.onSuccess(str)
                        } else if (count == maxCount) {
                            emitter.onComplete()
                        }
                    }
                }
            }, data, activity)
        }
    }

I still did not test this implementation thoroughly.

We released v3.1.1 of the SDK which has a fix for this issue.

Hi all, quick update here, we have the solution internally in place, we will be releasing the fix in an SDK update soon. Will update here once we do.

Hi @VvoidVano. Sorry that I forgot to post the update. We’ve determined that the SDK currently doesn’t receive the new link data in the following case only:

  1. App is in foreground
  2. Notification received with Branch link
  3. Notification tapped

The problem is that the SDK doesn’t check the Intent in this case, because the Activity state doesn’t call onResume when it’s in foreground and a notification is clicked. Because it’s isolated to a rare edge case, we haven’t prioritized a fix but we’re looking into it this week actually. cc @apeterson-branch

Hey @ibracero - Can you post a link to you SplashActivity.java and manifest code that I could review? Perhaps share a gist? I guarantee it’s one of the above things that’s causing this. If you’re not comfortable sharing in the public thread so others can learn, please send a note to alex@branch.io with this info and I’ll work with you 1 on 1, then post the solve here.