[英]How do I hide or suppress authentication popups in a webview?
我制作了一個經過身份驗證的搜索網絡視圖,該Webview在登錄時通過用戶名和密碼進行身份驗證。 每次我通過搜索進入Web視圖時,都會彈出已登錄用戶的身份驗證消息(我認為錯誤代碼為410)。 如何隱藏或隱藏相同內容?
我應該使用以下代碼嗎?
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);
}
如果是這樣,我該如何使用代碼來抑制或隱藏彈出窗口?
將以下實現的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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.