2013-09-30 68 views
0

我做了一個經過驗證的搜索網頁視圖,它在登錄時通過用戶名和密碼進行身份驗證。每次我通過搜索在webview上,它都會彈出用戶已經登錄的認證信息(我相信errorcode 410)。我如何壓制或隱藏它?如何在web視圖中隱藏或隱藏身份驗證彈出窗口?

我應該使用下面的代碼嗎?

public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 
    Toast.makeText(view.getContext(), "Authentication Error", Toast.LENGTH_LONG).show(); 

    if (errorCode == 410) { 
     //webview.setHttpAuthUsernamePassword(host, realm, username, password); 
     // Show alert to enter username and password. 
     // Then, when those are entered in the alert, 
     // set it through the setHttpAuthUsernamePassword(...) 
     // shown below and then reload the site. 
    } 
    super.onReceivedError(view, errorCode, description, failingUrl); 
} 

如果是這樣,我該如何去抑制或隱藏代碼彈出?

+0

那麼,我絕對不會使用HTTP 410(請參閱[RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html))。你可能會想到401.就抑制彈出窗口而言,你必須找出/給出更多關於它如何顯示或者它的代碼的信息。 – kabuko

回答

0

以下實施onReceivedHttpAuthRequest方法添加到您的WebViewClient類:

.... 

    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 
     .... 
    } 

    @Override 
    public void onReceivedHttpAuthRequest(WebView view, final HttpAuthHandler handler, final String host, final String realm) { 
      // Replace SAVED_USERNAME and SAVED_PASSWORD with your authentication details. 
      handler.proceed(SAVED_USERNAME,SAVED_PASSWORD); 
    } 

} 

documentation page for onReceivedHttpAuthRequest

+0

我有一個在我的代碼已經,仍然顯示彈出式身份驗證:@覆蓋 \t公共無效onReceivedHttpAuthRequest(的WebView視圖,最終HttpAuthHandler處理,最後字符串的主機,最後絃樂境界){ \t \t \t \t \t \t \t \t處理器.proceed(用戶名,密碼); \t} –