WebView: disable username and password cache request

Cableguy

Expert
Licensed User
Longtime User
Hi, is it possible to programatically prevent the user from beeing prompt about caching (remebered)!!!???

In my project I take a web form and pre-fill it and auto submit it, and I am using a WebView as a semafore to determine when the next phase (webpage loaded) is finished, and since a webview has its own cache, every user will be prompt about this, wich is a No-No...
 

warwound

Expert
Licensed User
Longtime User
Hi.

Is the native WebView WebSettings setSavePassword() method what you are looking for?

B4X:
Dim Obj1 As Reflector
Obj1.Target = MyWebView
Obj1.Target = Obj1.RunMethod("getSettings")
Obj1.RunMethod2("setSavePassword", False, "java.lang.boolean")

Martin.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
That didn't work...
Any other setting missing?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Ok, so after a few research I found these two WebView methods, Thanks to Warhound:

B4X:
public void setSaveFormData(boolean save)
 Since: API Level 1
Store whether the WebView is saving form data. 


public void setSavePassword(boolean save)
 Since: API Level 1
Store whether the WebView is saving password

Both belong to android.webkit.WebSettings class

But when trying with the suggestion of Warhound, it fails telling me that "NoSUchMethodException:SetSaveFormData"

This is my reflection code:
B4X:
   Obj1.Target = WebView1
   Obj1.Target = Obj1.RunMethod("getSettings")
   Obj1.RunMethod2("setSaveFormData",False, "java.lang.Boolean")
   Obj1.RunMethod2("setSavePassword",False, "java.lang.Boolean")
I have tried almost every combo I could think of, with logic, to no avail.
HELP!
 
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi again.

First take a look at this thread with an example of using the Reflection library to run the WebView 'clearCache' method:

http://www.b4x.com/forum/basic4android-updates-questions/10382-clear-webview-cache.html#post57810

See how the type argument uses a lower case b for boolean?

The code you posted uses an upper case B for Boolean.

It may be worth your while checking that you have the syntax 100% correct.

Basic4android - Reflection

You said your code failed with the error message:

"NoSUchMethodException:SetSaveFormData"

I note there is an upper case S for setSaveFormData - Java methods are case sensitive so be sure you use a lower case s in setSaveFormData.

Or is it that you need to use the lower case b for boolean and using the upper case B means you're calling the methods with an argument that the method is not overloaded to accept?

Anyway i'd try the lower case b for boolean to start with:

B4X:
Obj1.Target = WebView1
Obj1.Target = Obj1.RunMethod("getSettings")
Obj1.RunMethod2("setSaveFormData", False, "java.lang.boolean")
Obj1.RunMethod2("setSavePassword", False, "java.lang.boolean")

Martin.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
As I stated, I have tried every logic combo I could think of. lower and upper case
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi.

I've created a simple library to set these settings - it'll give us a chance to see if the problem is with the Reflection syntax or elsewhere.

This is the simple library:

B4X:
package uk.co.martinpearman.b4a.webviewsettings;

import android.webkit.WebView;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@Author("Martin Pearman")
@ShortName("WebViewSettings")
@Version((float) 1.0)

public class WebViewSettings {
   public static void setSaveFormData(WebView webView1, Boolean save){
      webView1.getSettings().setSaveFormData(save);
   }
   public static void setSavePassword(WebView webView1, Boolean save){
      webView1.getSettings().setSavePassword(save);
   }
}

I'll PM the link to the library to you so you can give it a try - i'd rather not post it on the forum.

Martin.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
@Andrew, You wouldn't be your-self if you were not pedantic at times...:icon_clap::icon_clap:

@Andrew: I have stepped back, and indeed the code does compile and gives no Error or Exception, but then again, it seems to do just that...Nothing...

@Martin: The same goes to the simple dll you so kindly prepared... it compiles and gives no errors nor exceptions, but I still get prompt about saving the UserName and Password used in this webform, with 3 options..."not now:save(remember):Forget about it"
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi again.

I updated the WebViewSettings library - fixed the error that agraham, pointed out re Boolean should have been boolean.

Then added a couple of new methods:

getSaveFormData(webView1 As WebView)

getSavePassword(webView1 As WebView)

The idea was that you'd be able to check if the settings had been applied.

Next i created a simple project to test the new library:

B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim WebView1 As WebView
   Dim WebViewSettings1 As WebViewSettings
End Sub

Sub Activity_Create(FirstTime As Boolean)
   WebView1.Initialize("")
   Activity.AddView(WebView1, 0, 0, -1, -1)
   
   WebViewSettings1.setSavePassword(WebView1, False)
   
   WebView1.LoadUrl("http://www.b4x.com/forum/index.php")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

It WORKS!

I've tried setting the URL loaded into WebView1 to a few different forums that i am a member of.
I run the project, complete the forum login and successfully login with no prompt to save my password.

If i re-start the emulator and run the project a second time then i am not still logged in by the way.

Did you use the setSavePassword() method BEFORE loading the webpage?

I'll PM you a link to my demo project and the new library.

Martin.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Hi again.

Did you use the setSavePassword() method BEFORE loading the webpage?

I'll PM you a link to my demo project and the new library.

Martin.

Hi Again Martin...

Yes I did, I am initializing and setting the params even before the load layout method...

I will give a try with you new dll...
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi Again Martin...

Yes I did, I am initializing and setting the params even before the load layout method...

I will give a try with you new dll...

Is the WebView initialised before you load the layout?
(Assuming your WebView is created in a layout not programmatically?)

If it's not yet initialised that may explain why the library is not working - but i'd expect you'd get an error running the library on a non-initialised WebView.

You can use the library getSavePassword(webView1 As WebView) method after your application has fully loaded/initialised to see if it reports True or False.

I got your PM and will try as you suggested - first i need to translate the page so i can register.

Martin.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I have FOUND it...

The save Username & Password prompt has 3 choices:
Not Now;Remeber;Never
We on the other hand have only two booleans to use, True or False, wich I think cover the two first options ( Not now;remember)
Therefore, there are only aplicable to a given site/form...
Since I was feeding my form to webview using loadhtml, but setting the paramswhen I loaded the login page from internet, the params were not being aplied to my form...
Placing the params just before loading the form with loadhtml did the trick...
(btw, setting the params AFTER loading the form made my app force-close everytime, any ideia why?)
Martin, thank you very much for your help...
 
Last edited:
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Look in the unfiltered log which should tell you what the exception was and where it was raised.

I have to say that I have never used the log a lot, even though I know it to be an important tool...
But now with my Galaxy S, with a custom ROM, I cannot even connect to the logger...and I dont know why!
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Nop not even...sometimes it connects, but no logger!
 
Upvote 0
Top