Branch.io initSession on Android returns null

Asked on March 5, 2017 in Technical.

I can’t Branch.io to initialize correctly on my Android app. Here is my AndroidManifest.xml:

  <!--  -->   <!--  -->    <!--  -->     <!--  -->
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.xxx.xxxx.app"

android:versionCode="150"

android:versionName="2.8.1 (150)" >
<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-permission android:name="android.permission.VIBRATE" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<uses-permission android:name="android.permission.RECORD_AUDIO" />

<uses-permission android:name="android.permission.CAMERA" />

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-feature android:name="android.hardware.camera" android:required="true" />

<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />

<uses-feature android:name="android.hardware.telephony" android:required="false"/>
<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme">
<!-- Branch.io values -->

<!-- <meta-data android:name="io.branch.sdk.TestMode" android:value="true" /> -->

<meta-data android:name="io.branch.sdk.BranchKey" android:value="@string/branch_key" />

<receiver android:name="io.branch.referral.InstallListener" android:exported="true">

<intent-filter>

<action android:name="com.android.vending.INSTALL_REFERRER" />

</intent-filter>

</receiver>

<activity

android:name=".activities_fragments.CXMainActivity"

android:screenOrientation="portrait"

android:configChanges="orientation|keyboardHidden|keyboard|screenSize"

android:windowSoftInputMode="adjustPan">
<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>
<intent-filter>

<data android:scheme="@string/branch_uri_scheme" android:host="@string/branch_host" />

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />

<category android:name="android.intent.category.BROWSABLE" />

</intent-filter>
</activity>

</application>
</manifest>

 

This is my main activity code:

 

protected void onStart() { super.onStart(); if(!initiatedBranchDeepLinks) { // Configure Branch.io initiatedBranchDeepLinks = true; Branch branch = Branch.getInstance(); branch.initSession(new Branch.BranchReferralInitListener(){ @Override public void onInitFinished(JSONObject referringParams, BranchError error) { if (error == null) { // params are the deep linked params associated with the link that the user clicked -> was re-directed to this app // params will be empty if no data found // ... insert custom logic here ... String message = "Branch.io onInitFinished. Params: " + referringParams.toString(); Log.d(TAG, message); } else { Log.i(TAG, error.getMessage()); } } }, this.getIntent().getData(), this); } }

 

I got a different app up and running on Android and they seem to be the same but for some reason, when I call branch.initSession(…), it returns a null. Any ideas?

 

Mobility Initiative — Developer
2 Answer(s)
Answered on March 5, 2017.

Here is the code formatted (sorry):

protected void onStart()
{
    super.onStart();
    if(!initiatedBranchDeepLinks) {
        // Configure Branch.io
        initiatedBranchDeepLinks = true;
        Branch branch = Branch.getInstance();
        branch.initSession(new Branch.BranchReferralInitListener(){
            @Override
            public void onInitFinished(JSONObject referringParams, BranchError error) {
                if (error == null) {
                    // params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
                    // params will be empty if no data found
                    // ... insert custom logic here ...
                    String message = "Branch.io onInitFinished. Params: " + referringParams.toString();
                    Log.d(TAG, message);

                } else {
                    Log.i(TAG, error.getMessage());
                }
            }
        }, this.getIntent().getData(), this);
    }
}
Mobility Initiative — Developer
Answered on March 6, 2017.

Here is our Branch Test Bed app: https://github.com/BranchMetrics/android-branch-deep-linking/tree/master/Branch-SDK-TestBed

Can you use this as a reference and see what you are doing incorrectly?

Developer
Commented on March 6, 2017.

I’ve gone through that and it seems the same.  I’ve even got this running on a different Android app.  That is why I’m confused.  Is there any other code I can offer that might give you some insights?

Mobility Initiative — Developer
Commented on March 12, 2017.

Hey sure – please write to our integrations team with details here. We will look into it :). Thanks!

Developer