BasicAuthentication in android for webview not working

Tags: , , ,



Hi I want to open this url http://3864.cloud-matic.net/ from my android webview and I have tried many ways but the app even not opens mainActivity. What I have tried is below.

 public void onCreate(Bundle state) {
    super.onCreate(state);
    setContentView(R.layout.main);
    WebView webView = (WebView) findViewById(R.id.webView1);
    webView.setHttpAuthUsernamePassword("cloud-matic.net/",     "realm", username, password);
    webView.loadUrl("http://3864.cloud-matic.net/");
}

Please give me idea where I am wrong. Ali

Answer

webview.setWebViewClient(new MyWebViewClient ());

private class MyWebViewClient extends WebViewClient {
    @Override
    public void onReceivedHttpAuthRequest(WebView view,
            HttpAuthHandler handler, String host, String realm) {
        handler.proceed("me@test.com", "mypassword");
    }
}

This is most voted solution there I am not sure where to set the URL to open.Please suggest.



Source: stackoverflow