javaandroidbranch.io

Trouble with init branch.io


I use branch.io for work with app link. AndroidManifest has intent-filter for Branch URI scheme:

<intent-filter>
    <data android:scheme="***" android:host="open" />
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

Also AndroidManifest has intent-filter for App Links:

<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="https" android:host="***.app.link" />
            <data
                android:host="***-alternate.app.link"
                android:scheme="https"/>
            <data
                android:host="***.test-app.link"
                android:scheme="https"/>
            <data
                android:host="***-alternate.test-app.link"
                android:scheme="https"/>

LaunchMode for AppLinkActivity is singleTask. I init Branch in Application, in onCreate:

Branch.getAutoInstance(this);

After open AppLinkActivity I get instance and I init session:

Branch branch = Branch.getInstance(getApplicationContext());
   branch.initSession((referringParams, error) -> {
        LogFileUtil.writeLog("Finish init session");
        if (error == null) {
            //Кое что делаю
        } else {
           //Кое что делаю
        }
    }, this.getIntent().getData(), this);

When I open my app across AppLink referringParams isn't empty. And I can get required data. But when app is open and I click AppLink from other app, that referringParams is empty. I think the problem is init Branch. How I can fix it?


Solution

  • Solution - you need to make AppLinkActivity class main. This activity must have one more intent-filter:

    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>