How do you add custom HTTP headers to Chrome Custom Tabs?

Matt Quigley picture Matt Quigley · Feb 15, 2016 · Viewed 8k times · Source

With standard Android WebViews, you use WebView.loadUrl(String url, Map<String, String> additionalHttpHeaders). How do you add your additional headers with Chrome Custom Tabs?

Answer

Nikola Despotoski picture Nikola Despotoski · Feb 15, 2016

I'm not sure if you can send headers or anything related to the http request besides the url. I hope future versions will allow sending headers in Bundle when you establish CustomTabSession or so.

Entire http call is managed in CustomTabActivity.

Edit:

As of recent updates of the library, you can now add Bundle and pass it to the CustomTabsIntent intent as extra with key Browser.EXTRA_HEADERS

Bundle headers = new Bundle();
headers.putString("header1", "value1");
headers.putString("header2", "value2");
customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headers);