0

ログイン時にユーザー名とパスワードを介して認証を取得する認証済み検索 Web ビューを作成しました。検索で 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);
}

もしそうなら、コードでポップアップを抑制または非表示にするにはどうすればよいですか?

4

1 に答える 1

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);
    }

}

onReceivedHttpAuthRequest のドキュメント ページを参照してください。

于 2013-09-30T21:10:23.267 に答える