2

我正在使用 webview 来显示 google canlender,但想以编程方式传递 google 帐户,所以 setHttpAuthUsernamePassword() 函数应该是我需要的,但它根本不起作用。这是代码:

WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.setHttpAuthUsernamePassword("www.google.com", "", "email", "password");

    webview.setWebViewClient(new WebViewClient() {
        @Override 
        public void onReceivedHttpAuthRequest (WebView view, HttpAuthHandler handler, String host,String realm){ 
            handler.proceed("email","password"); 
            }
        } 

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
        }
    });

    webview.loadUrl("http://www.google.com/calendar/");

如果您有任何想法来实现这一点,请告诉我。我试图搜索很多,但没有看到任何有用的。

4

1 回答 1

0

您正在尝试使用大多数 Web 服务不支持的 HTTP 身份验证 (http://en.wikipedia.org/wiki/Basic_access_authentication)。您需要拥有有效的 Google cookie,这些cookie 仅在您使用密码手动登录时设置。

于 2012-03-28T13:56:07.650 回答