1

I was reading up on Google Invites: https://developers.google.com/app-invites/android/guides/app and also branch.io: https://dev.branch.io/recipes/content_sharing/android/#routing-to-content-within-your-android-app

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.

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".

Branch.io also has a built in "native share sheet" but I don't think its as advance / nice as Google Invites.

I would like to use the Branch.io deeplinks with Google Invites interface for content sharing.

What I'm struggling with is to merge the two.

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:

@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);
        }
    }
}

Branch.io tells android to intercept the intent in the onStart method:

@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);
}

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?

Simon
  • 19,658
  • 27
  • 149
  • 217

1 Answers1

3

I dropped the branch SDK into google's app invite example and tried a few things. It seems that you can't feed a branch URL into the AppInviteInvitation IntentBuilder as a deep link without the link being turned into a google deep link. You could set the message itself to a Branch URL, setMessage(url), and possibly feed in a NULL URI for the deep link, but that's a bit hackish. I tried this myself, the e-mail feature half worked, but texting did not.

The default way to generate and share a branch link without the share sheet is as follows:

BranchShortLinkBuilder shortUrlBuilder = new BranchShortLinkBuilder(MainActivity.this)
        .addTag("tag1")
        .addTag("tag2")
        .setChannel("channel1")
        .setFeature("feature1")
        .setStage("1")
        .addParameters("name", "test name") // deeplink data - anything you want!
        .addParameters("message", "hello there with short url")
        .addParameters("$og_title", "this is a title")
        .addParameters("$og_description", "this is a description")
        .addParameters("$og_image_url", "https://imgurl.com/img.png");

// Get URL Asynchronously
shortUrlBuilder.generateShortUrl(new Branch.BranchLinkCreateListener() {
    @Override
    public void onLinkCreate(String url, BranchError error) {
        if (error != null) {
            Log.e("Branch Error", "Branch create short url failed. Caused by -" + error.getMessage());
        } else {
            Log.i("Branch", "Got a Branch URL " + url);

            Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
                    .setMessage(url)
                    .setDeepLink(Uri.parse(url))
                    .setCustomImage(Uri.parse(getString(R.string.invitation_custom_image)))
                    .build();
            startActivityForResult(intent, REQUEST_INVITE);


        }
    }
});

As for which should you use to intercept the intent: use Branch.initSession for Branch links, and use AppInviteReferral.hasReferral(intent) for google links. Intertwining the services for the point of a better share dialog is not the direction that I would take. Instead, use a branch link (they pass data through install faster than the Android SDK can) with a custom share dialog, there are many ways to build custom dialogs, google around / checkout github.

Please let me know if you have any other questions or require additional information, I'm happy to help.

Evan
  • 749
  • 6
  • 11
  • Thanks for your help. This is useful info. Does Facebook App Invites as a content sharing mechanism integrate better with Branch.io? – Simon Oct 24 '15 at 08:05
  • I just dropped the FB SDK into an app with Branch. Sent out a few invites and nothing seems to be showing up for people, no push notif, and I'm not even sure where FB houses app invites. Conversion rates for App Invites -> sign-ups are notoriously bad, again I would suggest a custom share dialog. – Evan Oct 26 '15 at 18:52