问题
I'd like to use the user's Gmail username and password to automatically login to Gmail inside a WebView. Is there any existing code how to do this, as I'm having trouble with it (which hidden fields need to be posted, getting/re-injecting the cookie).
I have tried to simply fill in the username/password-fields using JavaScript, which works, but on submitting the login-form (using JavaScript again), the WebView asks the users whether he/she wants the password to be saved, which I need to avoid (to make it truly automatic).
Thanks,
Nick
回答1:
WebSettings mWebSettings = mWebView.getSettings();
mWebSettings.setSavePassword(false);
mWebSettings.setSaveFormData(false)
Try this, not sure if both setSave[...] methods are required though.
But wait: Assuming you really just simply fill the login-form with JavaScript, do you store the password in plain text? If so, you shouldn't do that, not only due to security issues. I assume you're asking the user for his/her password via a Dialog. Asking for the password seems suspicious to a lot of users.
I suggest learning how to save and restore cookies instead.
来源:https://stackoverflow.com/questions/11352792/automatically-login-to-gmail-using-a-webview