How to open emails in Android to support web_only use case
There are 2 options to support the web-only use case in Android to open a universal email link:
- Remove the CTD from the manifest file, this will let all the links coming from the email to open as web_only. In cases where the apps need to open after clicking the branch link, URI scheme would serve that use case.
- If you want to use applinks and still have the email links open web_only, then add the following code in the Android app to support the web_only logic.
@Override
public void onStart() {
super.onStart();
Branch.getInstance().initSession(new Branch.BranchReferralInitListener() {
@Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
//logic to handle webonly routing
String webOnlyParam = referringParams.optString("$web_only");
if(!webOnlyParam.isEmpty()) {
if(webOnlyParam.contentEquals("true")) {
String url = referringParams.optString("$canonical_url");
if(!url.isEmpty()) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
} else { Log.i("Tag","missing $canonical_url"); }
}
} else { //Logic to handle routing in app }
}
}
}, this.getIntent().getData(), this);
}
Updated about 2 months ago