Android- EXTRA_HEADERS is not reflecting in updated Chrome version greater than 83

Viewed 1137

Earlier the EXTRA_HEADERS passed to the customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headers), was working fine. After Chrome updated to 83, it stopped passing the header data.

   public static void startCustomTab(String url, Context context) {
    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    CustomTabsIntent customTabsIntent = builder.build();
    builder.setShowTitle(true);
    Bundle headers = new Bundle();
    headers.putString(context.getString(R.string.type), "android");
    headers.putString(context.getString(R.string.source), "app");
    customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headers);
    customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    customTabsIntent.launchUrl(context, Uri.parse(url));
}
2 Answers

I'd like to elaborate a bit on the accepted answer. The Chrome 83 indeed removed the possibility to add custom headers, yet Chrome 86 reverted this functionality under certain strict conditions. See https://developers.google.com/web/android/custom-tabs/headers. Just follow an example from https://github.com/GoogleChrome/android-browser-helper/tree/master/demos/custom-tabs-headers.

TD;DR - you must own both app and website for making it work as the changes in app and The Digital Asset Links protocol file (website address (...)/.well-known/assetlinks.json) are needed.

Be sure to follow the tutorial and example precisely. In my case I stumbled with the one detail - CustomTabsIntent Builder needs a CustomTabsSession object set up.

Code changes in Chromium project indroducing a change can be found here: https://chromium-review.googlesource.com/c/chromium/src/+/2311582

Related