SilentGrove_99
SilentGrove_99

Reputation: 731

Is there a way to make android webview remember passwords?

Hi i made an android app that uses just a webview to look at my ip webcam, but my webcam asks username and a password everytime i open the app: enter image description here

Is there a way to make android webviews remember those passwords, so i don't have to enter them every time?

I am using Visual studio, c# and Xamarin.

I should also mention, that i am new to programming especially on android, Thanks.

Upvotes: 0

Views: 1217

Answers (1)

kris larson
kris larson

Reputation: 30985

The WebViewClient class has a callback method OnReceivedHttpAuthRequest which is invoked by the WebView when the server wants a user name and password. One of the parameters on this method is an HttpAuthHandler interface. You control the authorization request by calling methods on this handler.

So the solution is to create a WebViewClient subclass that overrides OnReceivedHttpAuthRequest and calls the appropriate method on the HttpAuthHandler. Then set your WebView to have an instance of this subclass.

Here's the link to the Xamarin documentation: OnReceivedHttpAuthRequest - Xamarin

    .
    .
    .
    var client = new MyWebViewClient();
    WebView web = FindViewById<WebView>(Resource.Id.webView1);
    web.SetWebViewClient(client);
    .
    .
    .


class MyWebViewClient : WebViewClient {

    public override void OnReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, string host, string realm) {

        handler.Proceed(username, password);
    }
}

Upvotes: 1

Related Questions