gpt4 book ai didi

android - Webview 在更新 chrome 76 后显示空白页面

转载 作者:行者123 更新时间:2023-11-29 22:50:32 26 4
gpt4 key购买 nike

我正在开发一个使用 WebView 显示信息的项目,我使用 shouldInterceptRequest 添加 header 。一切正常但在我更新 chrome 76 后,它显示空白页面,并且只调用了 shouldInterceptRequest。

webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setLoadWithOverviewMode(false);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setSupportMultipleWindows(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.clearCache(true);
webView.getSettings().setAppCacheEnabled(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
webView.setWebViewClient(new WebViewClient() {

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Nullable
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
Log.d("TAG", "shouldInterceptRequest: 2");
if (!checkFirstLoad) {
try {
checkFirstLoad = true;
Request req;
OkHttpClient httpClient = new OkHttpClient();
req = new Request.Builder()
.url(PA_URL.trim())
.addHeader("Pa-Token", token)
.addHeader("Pa-Redirect", url)
.addHeader("Pa-App-Token", randomString())
.addHeader("Pa-App-Encrypt", md5(deviceId+oldToken)).build();

Response response = httpClient.newCall(req).execute();
return new WebResourceResponse(MimeTypeMap.getFileExtensionFromUrl(request.getUrl().toString()),
response.header("content-encoding", "utf-8"),
response.body().byteStream());
} catch (IOException e) {
e.printStackTrace();
return null;
}
} else {
return null;
}
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
Log.d("TAG", "shouldOverrideUrlLoading: "+url);
return true;
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString());
Log.d("TAG", "shouldOverrideUrlLoading: "+request.getUrl().toString());
return true;
}

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
Log.d("TAG", "onPageStarted: "+url);
}

@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
Log.d("TAG", "onPageFinished: "+url);
}

@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
handler.proceed();
Log.d("TAG", "onReceivedError: "+error);
}

@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
progressBar.setVisibility(View.GONE);
Log.d("TAG", "onReceivedError: "+error);
}

@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
progressBar.setVisibility(View.GONE);
Log.d("TAG", "onReceivedError: "+ description);
}
});

webView.loadUrl(url);

我尝试了一些解决方案:this , this但没有工作。我该如何解决这个问题?

最佳答案

发生这种情况是因为您启用了 dom 存储。从 chrome 中清除缓存并清除应用程序数据,卸载并再次运行。它在我的情况下很有用。希望它也适用于您的情况

关于android - Webview 在更新 chrome 76 后显示空白页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57984596/

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