title: Android: Using Branch.io to generate deeplinks and Google Invites for content sharing
body: <p>I was reading up on Google Invites: <a href="https://developers.google.com/app-invites/android/guides/app" rel="nofollow">https://developers.google.com/app-invites/android/guides/app</a> and also branch.io: <a href="https://dev.branch.io/recipes/content_sharing/android/#routing-to-content-within-your-android-app" rel="nofollow">https://dev.branch.io/recipes/content_sharing/android/#routing-to-content-within-your-android-app</a></p>
  
  <p>Google Invites seems to excel at Content Sharing, providing an interface to select from Google all the people you want to send the deep link to your app.</p>
  
  <p>Branch.io seems to excel at generating deeplinks and their shorturl would contain all the data needed by an app in their "Embed key/value deep link metadata".</p>
  
  <p>Branch.io also has a built in "native share sheet" but I don't think its as advance / nice as Google Invites.</p>
  
  <p>I would like to use the Branch.io deeplinks with Google Invites interface for content sharing.</p>
  
  <p>What I'm struggling with is to merge the two.</p>
  
  <p>When someone clicks on the Google Invites link, the android app opens and inside the onCreate method, the following code runs to intercept the intent:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      // ...
  
      if (savedInstanceState == null) {
          // No savedInstanceState, so it is the first launch of this activity
          Intent intent = getIntent();
          if (AppInviteReferral.hasReferral(intent)) {
              // In this case the referral data is in the intent launching the MainActivity,
              // which means this user already had the app installed. We do not have to
              // register the Broadcast Receiver to listen for Play Store Install information
              launchDeepLinkActivity(intent);
          }
      }
  }
  </code></pre>
  
  <p>Branch.io tells android to intercept the intent in the onStart method:</p>
  
  <pre><code>@Override
  public void onStart() {
      super.onStart();
  
      Branch branch = Branch.getInstance();
  
      // If NOT using automatic session management
      // Branch branch = Branch.getInstance(getApplicationContext());
  
      branch.initSession(new BranchReferralInitListener(){
          @Override
          public void onInitFinished(JSONObject referringParams, Branch.BranchError error) {
              if (error == null) {
                  // params are the deep linked params associated with the link that the user clicked before showing up
                  // params will be empty if no data found
                  String pictureID = referringParams.optString("picture_id", "");
                  if (pictureID.equals("")) {
                      startActivity(new Intent(this, HomeActivity.class));
                  }
                  else {
                      Intent i = new Intent(this, ViewerActivity.class);
                      i.putExtra("picture_id", pictureID);
                      startActivity(i);
                  }
              } else {
                  Log.e("MyApp", error.getMessage());
              }
          }
      }, this.getIntent().getData(), this);
  }
  </code></pre>
  
  <p>If I use both Branch.io and Google Invites, which code should I use to intercept the intent that would start the android app when I click on the deeplink?</p>