2011-01-26 66 views
2

我正在使用webview來顯示谷歌canlender但希望通過谷歌帳戶programmatic-ally,所以setHttpAuthUsernamePassword()函數應該是我所需要的,但它根本不起作用。這裏是代碼:Android如何將谷歌帳戶傳遞給webview

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/"); 

如果您有任何想法使這工作,請讓我知道。我試圖搜索很多,但沒有看到任何有用的東西。

+0

我認爲這將永遠不會工作,因爲即使使用谷歌api Java客戶端,我們仍然需要用戶輸入授權。點擊此處http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html。請糾正我,如果.... – thanhbinh84 2011-01-27 08:18:54

回答

0

您正在嘗試使用大多數Web服務不支持的HTTP身份驗證(http://en.wikipedia.org/wiki/Basic_access_authentication)。您需要擁有有效的Google Cookie,這些Cookie僅在您手動使用密碼登錄時才設置。