开发者

Retain username and password in Android WebView

开发者 https://www.devze.com 2023-01-26 20:26 出处:网络
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 开发者_如何学运维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:

  1. Save with JavaScript the login data with the onClick event in a cookie and restore them from the cookie if needed
  2. 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();
0

精彩评论

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

关注公众号