Reputation: 2695
I would like to set session Coockie
Im having problem with setting cookie in WebView. This is the code:
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.fragment_web, parent, false);
String co = GlobalSession.SESSION_ID; //m4mg2aleunei8fad1lvn8h6n67
String co_name = GlobalSession.COOKIE_NAME; //PHPSESSID
//set and load web View
CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(getActivity());
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.removeSessionCookie();
cookieManager.setCookie("192.168.70.103", GlobalSession.SESSION_ID);
cookieSyncManager.sync();
WebView mView = new WebView(getActivity());
mView = (WebView) v.findViewById(R.id.web_view);
mView.getSettings().setJavaScriptEnabled(true);
mView.setWebViewClient(new myWebViewClient());
mView.loadUrl("http://192.168.70.103/test.php");
return v;
}
In previous step I send username and pass to server, which respond to me with parameters such as SESSSION_ID and COOKIE_NAME...
in test.php I verify if the user is loged on.... Well its not, so I assume that setting cookie fails. How to set cookie properly is my question.
Upvotes: 0
Views: 1541
Reputation: 12341
You are setting the cookie incorrectly. Use the following syntax:
cookieManager.setCookie("192.168.70.103", String.format("%s=%s",
GlobalSession.COOKIE_NAME, GlobalSession.SESSION_ID));
Upvotes: 1