Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cookies in Android Apps

 
Ed Mahoney
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an app that has to go out to a webpage to create a userid. The userid is checked and then the user is sent to the next page. A cookie is passed back to the web browser to carry the information forward. However, in android, the cookie does not get passed to the next page. I've tried using the builtin web view, but each 'page' is treated as a separate web instance and doesn't pass the cookie to the next page. I've tried passing the user to the android browser, but that doesn't seem to work either.

The documentation in this area is not very good. Can you suggest a strategy to get the cookie and pass it to the next page?

Thanks,

Ed
 
Pratik Goswami
Ranch Hand
Posts: 136
Android Chrome Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Ed,

There are classes available in Android to store & set cookies.
Have you gone through CookieManager ?
Hope it will help you.

Thanks & Regards
Pratik Goswami
 
Daniel Trebbien
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ed, would you please clarify your setup? How do you "go out to a webpage to create a userid"? How is the user "sent to the next page"?

Also, you mention the web browser and a WebView. How are you using the Browser activity, and how are you using a WebView?
 
Ed Mahoney
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for not being more specific

Here is the code I use to launch the webview, this is an activity. This does display the proper page, but when the user clicks the link on that page, no cookie is sent to the server. My understanding is that the shouldOverrideURLLoading shuold keep the user in the same view and not create a new one. Is there something else I have to do?

Thanks,
ed



WebView webview = new WebView(this);

webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
setContentView(webview);
webview.loadUrl(my url here);
 
Daniel Trebbien
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using two activities (one for showing the WebView that the user uses to log in, another for showing a WebView to display pages that require authentication)?

I am experimenting with:

where session.php on 192.168.1.100 is:



PHP uses cookies for sessions, so because I see the same session ID between page refreshes, I know that the WebView is sending the PHPSESSID cookie.

It seems to be working fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic