我的 Android 应用升级到 API 29,所以我们需要从 Xwalkcorelibrary 更改为 WebView,运行应用时可以显示 HTML5,但此页面的内容不显示。
使用 WebView 时:
setContentView(R.layout.bookshelf_view);
mWebView = findViewById(R.id.web_view);
mWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString());
return true;
}
});
try {
WebSettings webSettings = mWebView.getSettings();
webSettings.setUserAgentString(webSettings.getUserAgentString() + " " + AndroidCore.getInstance().getApiVersion());
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAppCacheEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
mWebView.loadUrl("file:///android_asset/HTML5/index.html");
使用 Xwalkcorelibrary 时:
try {
Method getBridge = XWalkView.class.getDeclaredMethod("getBridge");
getBridge.setAccessible(true);
XWalkViewBridge xWalkViewBridge = null;
xWalkViewBridge = (XWalkViewBridge) getBridge.invoke(mXwalkView);
XWalkSettings webSettings = xWalkViewBridge.getSettings();
webSettings.setUserAgentString(
webSettings.getUserAgentString() + " " + AndroidCore.getInstance().getApiVersion());
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAppCacheEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
mXwalkView.setResourceClient(new MyResourceClient(mXwalkView));
mXwalkView.setUIClient(new MyUIClient(mXwalkView));
this.configureWebView();
mXwalkView.loadAppFromManifest("file:///android_asset/manifest.json", null)
那么我做错了什么?请帮我找出解决方案?