Reputation: 10330
I have an app that's using Branch.io and am in process of updating it to support Instant Apps. Part of this change will require using app links to navigate from one part of app to another.
The Activity that I'm opening is configured to use Branch.io (e.g. using instructions in https://dev.branch.io/marketing-channels/android-instant-apps/guide/) and includes following in it's onStart()
method. However I'm not seeing parameters I'm including in deep link in referringParams
.
Branch.getInstance().initSession(new Branch.BranchReferralInitListener() {
@Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
Log.d("Branch", "onInitFinished() with deep link data: " + referringParams);
}
});
Do I need to trigger opening of the branch link in particular way from Android code for this to work?
BTW referringParams
above does show +clicked_branch_link
being false
.
UPDATE
Just to clarify a few things. I'm trying for example to launch ActivityB
from ActivityA
using app deep link. ActivityB
includes <intent-filter>
as described in https://dev.branch.io/marketing-channels/android-instant-apps/guide/ for example. In ActivityA
I'm currently trying to open/create Branch.io link as follows (have also formed link directly, as is used in that android-instant-apps
sample for example, but that's not considered a "branch link")
HashMap<String, String> metadata = new HashMap<>();
metadata.put(PARAM, param);
BranchUniversalObject branchUniversalObject = new BranchUniversalObject().addContentMetadata(metadata);
LinkProperties linkProperties = new LinkProperties();
branchUniversalObject.generateShortUrl(context, linkProperties, (url, error) -> {
if (error == null) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
context.startActivity(intent);
}
});
If I try to open the url generated (by generateShortUrl
) directly on device (clicking on link for example) then ActivityB
is launched and I see the param I included in initSession
callback. If I try to open it using code above (navigating betweeen ActivityA
and ActivityB
then ActivityB
is launched but don't get the params (and +clicked_branch_link
is false
)
Upvotes: 2
Views: 2093
Reputation: 546
Sojan from Branch here If you are trying to deep link to a new feature from another instant app apk unfortunetely Branch is not supporting this feature now.
If you are trying to get deep link params on opening an activity B in a new feature from activity A from another feature in an installed app you can achieve it in the following way.
ActivityA.java
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("yourBranchLink"));
intent.putExtra("branch","yourBranchLink");
intent.putExtra("branch_force_new_session",true);
Hope this helps
Upvotes: 1
Reputation: 1045
In order to configure the Branch SDK with your Instant App supported Android App you can follow the steps below:
1. Initialize the Branch SDK Initialize the Branch SDK in the onCreate() method of your Application class. If you plan on deep linking from your Android Instant App to your full Android app after its installed, you'll need to add the line enablePlayStoreReferrer. This adds a delay to the initialization to wait for the Google Play Referrer, which can take up to a second.
public void onCreate() {
super.onCreate();
// This is needed to deferred deep link from an Android Instant App to a full app
// It tells the Branch initialization to wait for the Google Play Referrer before proceeding.
Branch.enablePlayStoreReferrer(1000L);
// Initialize the Branch SDK
Branch.getAutoInstance(this);
}
2. Add your Branch keys and register for Install Referrer
Instant Apps can be rather confusing as there are many different manifests, but you want to find the Manifest that contains your application tags. Make sure your Application class name is defined here, and then specify the Branch keys inside the application element.
<application
android:allowBackup="true"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:supportsRtl="true"
android:name=".MyApplication">
<!-- Set to true to use Branch_Test_Key -->
<meta-data android:name="io.branch.sdk.TestMode" android:value="false" />
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_app_live_key" />
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_app_test_key" />
<receiver android:name="io.branch.referral.InstallListener" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
3. Configure your Branch links as Android App Links
Assuming you've already configured Branch for Android App Links for your Android App the next step is to add the intent filter for App links support in your Application Tag. Make sure to replace the xxxx
with your link Domain. (If you haven't configured your full native app to use Branch as Android App Links you can follow the steps mentioned here and here.)
<application
......
<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="xxxx.app.link" />
<data android:scheme="https" android:host="xxxx-alternate.app.link" />
</intent-filter>
</application>
4. Retrieve Branch deep link data
Add Branch initSession in Activities which are configured to open from a link click in order to receive the deep link params. This will return the deep link data from the referring link.
protected void onStart() {
super.onStart();
Branch.getInstance().initSession(new Branch.BranchReferralInitListener() {
@Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
Log.d("Branch","onInitFinished() with deep link data: " + referringParams);
}
});
}
5. Configure the deep linking from Instant App to your Full App
To convert your user who just arrived in your Instant App to your full native app, Branch SDK provides convenient methods to check for app types and full app conversion. This eliminates the dependency on Google IA support SDK ('com.google.android.instantapp'). Here are some of the methods:
Branch.isInstantApp()
This convenience method checks whether the current version of app running is Instant App or Full Android App
Branch.showInstallPrompt()
This methods shows an install prompt for the full Android app, allowing you an easy way to pass Branch referring deep data to the full app through the install process.
Upvotes: 0