Search code examples
react-nativebranch.io

Trouble opening BranchIo deep links on Android with react navigation


I've been trying to integrate Branch into my React Native project. I can successfully create Branch Universal Object. When I click on it, it opens the app, but the only params that the branch listener picks up are:

{"+clicked_branch_link": false, "+is_first_session": false}

Here is the relevant portion of the AndroidManifest.xml:

      <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="branchfoodisgood" android:host="open" />
        <data android:scheme="https" android:host="fig.app.link" />
        <data android:scheme="http" android:host="fig.app.link" />
        <data android:scheme="https" android:host="fig.test-app.link" />
        <data android:scheme="http" android:host="fig.test-app.link" />
      </intent-filter>

These links open on iOS with the correct data.

Interestingly when the app is no open, the link works, but when it is previously opened it does not recognize the link.


Solution

  • In order to work around this - I had to modify the code from the react-native branch docs.

      // Override onNewIntent for Branch.io
      @Override
      public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        /**
         * Issue: The documentation provided
         * (https://help.branch.io/developers-hub/docs/react-native#android) was said to
         * include the followign lines:
         * 
         * if (intent != null &&
         * intent.hasExtra("branch_force_new_session") &&
         * intent.getBooleanExtra("branch_force_new_session", false))
         * {
         * RNBranchModule.onNewIntent(intent);
         * }
         * 
         * But this was causing an issue with opening the PDP from a deep link when the
         * session was already in progress
         * So I remove that code and always force a new branch seesion when a link is
         * opened
         * 
         * See issue here:
         * https://github.com/BranchMetrics/react-native-branch-deep-linking-attribution/issues/707
         * 
         */
        RNBranchModule.onNewIntent(intent);
      }
    
    

    There is a corresponding issue here discussing this with the maintainers.