gpt4 book ai didi

android - onReceivedHttpError : support for android version < 23 错误

转载 作者:太空狗 更新时间:2023-10-29 13:50:21 34 4
gpt4 key购买 nike

我正在开发一个加载 url 的解决方案。我需要获取 Http 错误,以便重新加载 url 以创建新 session 。

@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
Toast.makeText(getActivity(), "Unexpected error occurred.Reload page again.", Toast.LENGTH_SHORT).show();
if(errorResponse.getStatusCode() == 401){
customWebView.loadUrl(url);
}
}

但上面代码的问题在于它在 Marshmallow 中运行。任何人都可以建议我一个解决方案,我可以在 android 版本 < 23 以下出现错误吗?

最佳答案

onReceivedHttpError

void onReceivedHttpError (WebView view, 
WebResourceRequest request,
WebResourceResponse errorResponse)

通知主机应用程序在加载资源时已从服务器收到 HTTP 错误。

Can any one suggest me a solution where I can get error below android version < 23

onReceivedHttpError 添加到 API 级别 23。所以它不会在 23 以下工作。

尝试

.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
}

@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {

/*if(Build.VERSION.SDK_INT<23)
{
// You work
}*/
}

@Override
public void onReceivedHttpError(
WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {

/*if(Build.VERSION.SDK_INT >= 23)
{
// Your Work
}*/
}

@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler,
SslError error) {
}
});

仅供引用

onReceivedError

This method was deprecated in API level 23. Use onReceivedError(WebView, WebResourceRequest, WebResourceError) instead.

关于android - onReceivedHttpError : support for android version < 23 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48700403/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com