问题
I am working on a application where i want to add headers to browser in android. Its working pretty fine on Google chrome.
But this is not working on other available browsers like Firefox, UC browser, OperaMini, Dolphin
Below is the code that i tried.
Intent mIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(URL));
Bundle bundle = new Bundle();
bundle.putString(Constants.REQUEST_HEADER_TOKEN, "token");
bundle.putString(Constants.REQUEST_HEADER_AUTH, "Basic bfjdslfs");
mIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
startActivity(mIntent);
Any help will be appreciated.Thanks in advance.
回答1:
There is no requirement that browsers pay any attention to extras like EXTRA_HEADERS
, REQUEST_HEADER_TOKEN
, etc.
Either use WebView
or live without the headers always being added.
回答2:
This solution definitely works with mobile chrome browser ( haven't test ob others)
Intent mIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(URL));
Bundle bundle = new Bundle();
bundle.putString("Authorization", "Basic " + token);
mIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
startActivity(mIntent);
However be careful with links for files that can be opened in some other default application.
In my case, there was problem with pdf Every link that ends with .pdf (http://lol.com/test.pdf) is opening not in web browser but in some pdf reader and then EXTRA_HEADERS aren't sent.
来源:https://stackoverflow.com/questions/38438069/adding-custom-headers-on-all-browsers