c12
c12

Reputation: 9827

Android ICS WebViewClient onReceivedHttpAuthRequest No Longer Returns UserId and Password

I have a WebView that works fine with previous releases of the Android OS, but has issues loading for Ice Cream Sandwich devices. The page I'm attempting to load require BASIC AUTH and is passing in a query string parameter for non security purposes.

The issue is with the WebViewClient.onReceivedHttpAuthRequest method:

 String[] up = view.getHttpAuthUsernamePassword(host, realm);

Its returning a null array instead of the user's id and password. Anyone know why this acts differently in Android ICS? I get the user id and password for other versions of the OS.

Full Code:

public class DestinationWebViewScreen extends Activity{

    WebView mWebView;

    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.destination_webview);

            mWebView = (WebView) findViewById(R.id.social_destination_webview);
            mWebView.getSettings().setJavaScriptEnabled(true);
            mWebView.getSettings().setLoadsImagesAutomatically(true);
            mWebView.clearCache(true);
            mWebView.clearFormData();
            mWebView.clearHistory();   
            mWebView.getSettings().setBuiltInZoomControls(true); 

            mWebView.setHttpAuthUsernamePassword("HOST_OF_WEBAPP","Spring Security Application", "USERID", "PASSWORD");

            mWebView.setWebViewClient( new WebViewClient() { 
                @Override 
                public void onReceivedHttpAuthRequest  (WebView view, 
                        HttpAuthHandler handler, String host,String realm){ 

                    String[] up = view.getHttpAuthUsernamePassword(host, realm); 
                    if( up != null && up.length == 2 ) { 
                        handler.proceed(up[0], up[1]); 
                    } 
                }


                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    super.onPageStarted(view, url, favicon);

                    if(progressDialog != null){
                        progressDialog.dismiss();
                    }

                    showProgressbar();
                }


                @Override
                public void onPageFinished(WebView view, String url) {              
                    super.onPageFinished(view, url);

                    dismissProgressDialog();
                }

                @Override
                public void onReceivedError(WebView view, int errorCode,
                        String description, String failingUrl) {                
                    super.onReceivedError(view, errorCode, description, failingUrl);

                    dismissProgressDialog();


                }



            });

    mWebView.loadUrl("https://webapphost/webapp?customerId=0-222293");

    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);        
            registerReceiver(networkStateReceiver, filter);
    }

    public void showProgressbar() {
        progressDialog = new CustomProgressDialog(SocialDestinationWebViewScreen.this); 
        progressDialog.getWindow().setBackgroundDrawable(getResources().getDrawable(android.R.color.transparent));
        progressDialog.setMessage(SocialDestinationWebViewScreen.this.getResources().getString(R.string.loading));
        progressDialog.show();
    }


    void dismissProgressDialog(){

        if(progressDialog != null){
            progressDialog.dismiss();
        }

        progressDialog = null;
    }

}

Upvotes: 0

Views: 3067

Answers (1)

manelizzard
manelizzard

Reputation: 1058

Have you checked what you receive in #onReceivedHttpAuthRequest?

I just fixed what you say. It seems that ICS returns as "host" not only the host, but the port also, something like: HOST_OF_WEBAPP:80.

Because of that, what you store as "HOST_OF_WEBAPP" is not retrieved if you receive "HOST_OF_WEBAPP:80" in #onReceivedHttpAuthRequest.

Give it a try!

Upvotes: 3

Related Questions