Passing Headers while using Browser Intent

戏子无情 提交于 2019-12-09 09:27:17

问题


I want to pass some headers while opening a web page. Right now, I'm doing something like : browserIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(data.link)); startActivity(browserIntent);

Now I'm stuck as I dont know how to pass headers using browserIntent. I've tried using browserIntent.putExtra() but it doesn't work.

Can anyone please help.!!


回答1:


This was my biggest question in the last 2days, too! And I found it!!!

I have a Map object that I stored header information. Then the following:

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
Bundle bundle = new Bundle();
if(mExtraHeader!=null){
 for(String key: mExtraHeader.keySet()){
  bundle.putString(key, mExtraHeader.get(key));
 }
}
i.putExtra(Browser.EXTRA_HEADERS, bundle);
startActivity(i);

One problem is...I guess this would only work with the default browser and other browsers wouldn't have Browser.EXTRA_HEADERS I suppose. Resource: http://gitorious.org/rowboat/packages-apps-browser/blobs/a563d09392905140893d7a017dd63721577e1953/src/com/android/browser/BrowserActivity.java




回答2:


As Satoshi guessed, this doesn't work with Chrome. If you need to pass headers, you'll need to create your own WebView and load the url with a map of headers. Assume that mWebView is a reference to your webview.

Map<String, String> headers = new HashMap<>();
headers.put("referer", "http://some-referer");
mWebView.loadUrl(mUrl, headers);


来源:https://stackoverflow.com/questions/3750361/passing-headers-while-using-browser-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!