27

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?

Pablo Claus
  • 5,886
  • 3
  • 29
  • 38
aichingm
  • 738
  • 2
  • 7
  • 15

6 Answers6

40

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.

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
  • 1
    This method was deprecated in API level 18. Saving passwords in WebView will not be supported in future versions. – Kirk Hammett Nov 08 '13 at 08:51
24

@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"
    }
Tal Kanel
  • 10,475
  • 10
  • 60
  • 98
  • 2
    All right, just change Build.VERSION.SDK_INT <= 18 to Build.VERSION.SDK_INT < 18. In API 18 already deprecated. – Nik Dec 09 '13 at 07:40
  • 2
    @Nik: in API level 18 this method is deprecated, but would work. from level 19 - attempt to call this method would throw "no such method exception" – Tal Kanel Feb 13 '14 at 18:30
  • The condition is not necessary. The call is compatible with API 18, 19, ... it just doesn't do anything. "deprecated" does not mean the method is removed. – pzulw Mar 21 '14 at 18:06
  • @pzulw: I know that deprecated != removed. generally ,using long long ago deprecated methods might cause unexpected behavior and even lead to application crashes, and might be even removed!!! that's because the developer who declared the deprecation decided this method is not relevant anymore, and probably it using test case won't be taking in considerations and bug fixes / code change around this method.http://stackoverflow.com/questions/2941900/is-it-wrong-to-use-deprecated-methods-or-classes-in-java – Tal Kanel Mar 21 '14 at 18:25
  • you'll have to agree with me that it would be better to not invoke them at all then taking that chance! – Tal Kanel Mar 21 '14 at 18:28
  • It works on API 18, too. It might not removed on API 18. If I call it, I cannot see any popup about saving password. I tested on Galaxy4 with API 18. – cmcromance May 20 '14 at 03:25
  • @Maria: glad it help ya :) – Tal Kanel Aug 26 '15 at 11:06
  • I know it's deprecated but I have a HUAWEI ALE-L04 test device running Android 5.1 (that's API level 22) and the only way I found to make the prompt disappear for that device was to call this deprecated method. They say it's deprecated starting with API 18 and won't have any effect, without offering an equivalent, which implies that there should be no need to call this method in the first place, but there seems to be some cases for some devices where it's actually still useful... – androidseb Aug 28 '17 at 13:04
2

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);
timv
  • 3,346
  • 4
  • 34
  • 43
2

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);
Kenny
  • 805
  • 8
  • 19
0

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.

Hitin
  • 442
  • 7
  • 21
0

If it's in a WebView... just add autocomplete="off" attribute to form?

An0nC0d3r
  • 1,275
  • 13
  • 33