Reputation: 796
I'd like to know how to prevent an Android WebView form asking to save the "password-data" from a html form?
May you can help me out on this?
Upvotes: 28
Views: 17059
Reputation: 815
Its not so depreciated as you might think, I had to remove the version check as I was getting the prompt on a Huawei 5.01 device and disable FormData as well...
webview.getSettings().setSavePassword(false);
webview.getSettings().setSaveFormData(false);
Upvotes: 3
Reputation: 1303
If it's in a WebView... just add autocomplete="off" attribute to form?
Upvotes: 0
Reputation: 442
I have all the above and used the app on my Huawei Ascend P7, which is running higher than 18. But for some reason I am still seeing a confirmation box saying "Do you want the browser to remember this password?"
What could be the reasons of this popup. I have tried the below code.
_viewSettings.setSavePassword(false);
if (Build.VERSION.SDK_INT <= 18) {
_viewSettings.setSavePassword(false);
}
_view.loadUrl(url);
Note: The above doesnt show any save message on Samsung devices.
Upvotes: 0
Reputation: 50588
Try this:
Get webview settings with .getSettings()
and set this method setSavePassword(false)
public void setSavePassword (boolean save)
http://developer.android.com/reference/android/webkit/WebSettings.html#setSaveFormData(boolean)
For those using API Level 18, please see Kirk Hammet's answer below.
Upvotes: 41
Reputation: 10785
@Nikola Despotoski answer was correct at the point of time he posted the answer, but this method is deprecated since API 18, and according to the documentation:
Saving passwords in WebView will not be supported in future versions
this means that by default in android 4.4 and above - the default would be "false", and this method would not be exist anymore at all.
if you want to make sure you compatible with all the different API levels, you should write:
if (Build.VERSION.SDK_INT <= 18) {
mWebView.getSettings().setSavePassword(false);
} else {
// do nothing. because as google mentioned in the documentation -
// "Saving passwords in WebView will not be supported in future versions"
}
Upvotes: 24
Reputation: 3366
Heres a code snippet for those like me who need to see it as it should be entered
WebView webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSavePassword(false);
Upvotes: 2