Retain username and password in Android WebView
I 开发者_如何学运维have a webpage which contains username and password fields. In Android WebView, I loads that page and enter the user credentials to login. Now if the user logs out and logs in again, I want the previous username and password values to be retained in the fields of the WebView where we enter the credentials. I have seen some methods like setHttpAuthUsernamePassword
,savePassword
like this in WebView class of Android. I've tried with these methods to save the credentials and tried to get the values by this method getHttpAuthUsernamePassword
. But it is not working. May I know how to do this using these methods or is there any other way to do this?
I know 2 possibilities:
- Save with JavaScript the login data with the
onClick
event in a cookie and restore them from the cookie if needed - Simply let the user decide if he want to store the login data (which is supported by the default android browser)
or try this,
CookieSyncManager.createInstance(thisActivity);
CookieManager.getInstance();
When webview loads try to use this coding, I'm not sure on this, sorry for that.
Activity thisActivity;
thisActivity = this;
CookieSyncManager.createInstance(thisActivity);
CookieSyncManager.getInstance().sync();
精彩评论