eyeballs
eyeballs

Reputation: 169

Android Branch IO referringParams is false

I'm handling branch io on Android now. It's weird. If I close my app first and click the link, the link leads me to my app and opens the page which is supposed to be shown. But If I open my app and click the home button, and click the link, the link leads me to ap.. but the page is not shown. I just could see the main page without routing by branch io.

here this is my code.

@Override
protected void onStart() {
    super.onStart();
    branchIO();
}

private void branchIO() {
    Branch branch= Branch.getInstance();

    branch.initSession(new Branch.BranchReferralInitListener(){

        @Override
        public void onInitFinished(JSONObject referringParams, BranchError error) {

            if (error == null) {
                try{
                    Log.d("log", referringParams.toString());
                    //...my routing logic...
                }catch(Exception e){
                    Log.e("log", "branch io error",e);
                }
            } else {
               Log.i("log", error.getMessage());
            }
        }
    }, this.getIntent().getData(), this);

    BranchIO.branchUniversalObject.generateShortUrl(this, BranchIO.linkProperties, new Branch.BranchLinkCreateListener() {
        @Override
        public void onLinkCreate(String url, BranchError error) {
            if (error == null) {
            }
        }
    });
}

If I close my app first, the log is this

D/log: {"$og_title":"₩230000", "~creation_source":5, "$og_description":"blah blah", "+click_timestamp":1512100123,........"}

but If I open my app first and put it in the background, the log is this

D/log: {"+clicked_branch_link":false,"+is_first_session":false}

I read many StackOverflow and GitHub pages but couldn't find the solution. Thanks for reading!

EDIT

I forgot to use this.setIntent(intent) in onNewIntent. so after adding this, It worked well.

@Override
public void onNewIntent(Intent intent) {
    this.setIntent(intent);
}

Thanks!

Upvotes: 2

Views: 1480

Answers (1)

aaron
aaron

Reputation: 381

Aaron from Branch.io here.

There might be a few reasons you are seeing this error. Here are a few:

  1. You aren't initializing Branch and handling deep linking in your Main/Splash activity.

  2. Your Main/Splash activity does not have the launchMode set to singleTask

  3. You aren't overriding onNewIntent() in your Main/Splash activity

  4. If you are using a CustomApplicationClass, make sure you are initializing Branch with Branch.getAutoInstance(this);

You can find an example Main/Splash activity here.

You can also check out our testbed application which is a complete working example of the Branch Android SDK here

Upvotes: 3

Related Questions