Android如何将google帐户传递给webview

标签 android webview google-calendar-api account

我正在使用 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/");

如果您有任何想法让这个工作成功,请告诉我。我试图搜索很多但没有看到任何有用的东西。

最佳答案

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

关于Android如何将google帐户传递给webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4802441/

相关文章:

google-calendar-api - 将事件设置为锁定

android:从嵌套的 JSON 对象中检索值到列表类型

android - 如何在一个布局中实现多个recyclerviews?

android - 如何对 android webview 进行 url 更改?

Android WebView对hr标签进行CSS修改

单个 .html 文件上的 Android WebView 给出 “net::ERR_CACHE_MISS”

ruby-on-rails - Google Calendar API v3 - 更新事件

android - 有没有办法在android中产生特定声压级的纯音?

Android WebView - history.go(-1)

http - Google Calendar V3 REST API 中的批量请求