Posted by Anuraj on Friday, December 13, 2013
This is post is about another hybrid application scenario. I had to implement this in one of our projects, the problem was like this, unlike other hybrid applications, this project had a native login screen, which will authenticate the user against a REST API service and once the authentication is successful, service will set an authentication cookie. And once authentication is completed, application will start a new activity, which will load the web application. If cookie is not present, the web application will show the Forms authentication screen.
Here is the implementation.
For accessing cookie from HttpWebRequest class, you need to create a CookieContainer class, and need to set CookieContainer property of HttpWebRequest.
After receiving the response from HttpWebRequest, you can access the cookies via HttpWebResponse.Cookies property.
You can set the cookie for WebView by getting the cookie manager instance and invoking SetCookie() method.
Here is CustomWebViewClient implementation.
Happy Programming :)
You can find the source code on github â€“ https://github.com/anuraj/CookieSharing