gpt4 book ai didi

API 21 及更高版本中的 Android webview 加载失败

转载 作者:太空宇宙 更新时间:2023-11-03 13:12:54 24 4
gpt4 key购买 nike

我有一个使用 WebView 并加载页面的 Android 应用程序。此应用适用于运行 API 16 或更高版本的 Android 设备

Android WebView 代码:

String URL = "https://sandbox.napas.com.vn/gateway/message";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);

webview = (WebView) findViewById(R.id.webview);

webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setAllowFileAccess(true);
webview.getSettings().setPluginState(PluginState.ON);
webview.getSettings().setDomStorageEnabled(true);
webview.getSettings().setAllowContentAccess(true);
webview.getSettings().setAllowFileAccessFromFileURLs(true);
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

webview.setWebChromeClient(new MyWebChromeClient());
webview.loadUrl(URL);

webview.setWebViewClient(new WebViewClient() {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {

view.loadUrl(url);
return true;
}

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}

@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
});
}

但是 webview 加载页面是空的并且有日志:

E/libEGL(25467): validate_display:255 error 3008 (EGL_BAD_DISPLAY)
W/AudioCapabilities(25467): Unsupported mime audio/evrc
W/AudioCapabilities(25467): Unsupported mime audio/qcelp
W/VideoCapabilities(25467): Unrecognized profile 2130706433 for video/avc
W/AudioCapabilities(25467): Unsupported mime audio/amr-wb-plus
W/AudioCapabilities(25467): Unsupported mime audio/mpeg-L1
W/AudioCapabilities(25467): Unsupported mime audio/mpeg-L2
D/ConnectivityManager(25467): CallingUid : 10063, CallingPid : 25467
D/ConnectivityManager.CallbackHandler(25467): CM callback handler got msg 524290
W/AudioCapabilities(25467): Unsupported mime audio/x-ms-wma
W/AudioCapabilities(25467): Unsupported mime audio/x-ima
W/AudioCapabilities(25467): Unsupported mime audio/qcelp
W/AudioCapabilities(25467): Unsupported mime audio/evrc
W/VideoCapabilities(25467): Unsupported mime video/wvc1
W/VideoCapabilities(25467): Unsupported mime video/x-ms-wmv
W/VideoCapabilities(25467): Unrecognized profile/level 32768/2 for video/mp4v-es
W/VideoCapabilities(25467): Unsupported mime video/wvc1
W/VideoCapabilities(25467): Unsupported mime video/x-ms-wmv
W/VideoCapabilities(25467): Unsupported mime video/x-ms-wmv7
W/VideoCapabilities(25467): Unsupported mime video/x-ms-wmv8
W/VideoCapabilities(25467): Unsupported mime video/mp43
W/VideoCapabilities(25467): Unsupported mime video/sorenson
W/VideoCapabilities(25467): Unsupported mime video/mp4v-esdp

请帮我解决这个错误。谢谢

最佳答案

我通过处理 ssl Error 找到了类似问题的解决方案。基本上覆盖 Webviewclient 对象中的函数 onReceivedSslError 并设置 handler.proceed( ),删除了问题。

      WebViewClient webClient = new WebViewClient() {
// Override page so it's load on my view only
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}

@Override
public void onPageStarted(WebView view, String url, Bitmap facIcon) {

mLayoutProgress.setVisibility(View.VISIBLE);

}

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

@Override
public void onPageFinished(WebView view, String url) {

mLayoutProgress.setVisibility(View.GONE);
}
};

关于API 21 及更高版本中的 Android webview 加载失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41631830/

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