开发者

Pass cookie to browser via Intent

开发者 https://www.devze.com 2023-01-16 01:24 出处:网络
I have saved a cookie in android. Now I want to pass it into my browser intent. Look at my current code:

I have saved a cookie in android. Now I want to pass it into my browser intent. Look at my current code:

Intent browser = new Intent("android.intent.action.VIEW",
                            Uri.parse("http://mypage.php/memberpagethatrequireacookie.php"));
//putExtra cannot take these arguments -> browser.putExtra("o开发者_开发百科rg.apache.http.cookie.Cookie", cookie);
startActivity(browser);

I want it to store temporarily in my browser so my member page loads successfully. My cookie are successfully created from the HTTP request and I assign it to a List<Cookie> cookie; Tell me if I should provide some more code.

Any ideas? Thanks in advance!


The Browser has no documented Intent extras, let alone one that would allow you to inject a cookie. And, of course, the user might be using a different browser.

You are welcome to use WebView in your application, and you can use the CookieManager to inject your cookie into the WebView's environment.


Here is the answer that uses android.proveder.Browser:

I have a Map object that I stored the header information I want to pass. 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);

Like the other guy mentioned, 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


The above code is working fine to set headers (thanks for it), but I wasn't able to set cookies that way. What I suspect is that if the web browser already has cookies stored for the target URL, it will overwrite cookies created using EXTRA_HEADERS.

0

精彩评论

暂无评论...
验证码 换一张
取 消