Jayasai Goutheman
Jayasai Goutheman

Reputation: 197

Custom alert box not loading in android WebView

In my application , I have a WebView to load a web app.The login is done using a alert box which takes username and password. when i try to load the URL in android browser the alert box appears like this. But when I try to load the same URL in my WebView it does not show any alert box .

After adding the following code

mwebView.setWebChromeClient(new WebChromeClient(){

            @Override
            public boolean onJsAlert(WebView view, String url, String message, android.webkit.JsResult result) {
                Log.d("JSALERT", message);
                new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true).show();
                result.confirm();
                return true;
            }
        });

WebView shows simple alert box messages , but it does not show that custom alert box(the method is not getting fired).

In my app WebView , I wanted to show the login alert (which includes login fields and Buttons) .if any one knows the solution pls share with me

Thanks in advance

Upvotes: 0

Views: 1070

Answers (1)

Mikhail Naganov
Mikhail Naganov

Reputation: 6861

Well, what you see in Browser isn't actually an "alert box" -- it's an HTTP authentication dialog. In order to handle it, you need to override WebViewClient.onReceivedHttpAuthRequest, see docs.

You can check the relevant code in Android Browser here and here.

Upvotes: 1

Related Questions