Android 网络视图和 loadData()
Android webviews and loadData()
我正在开发一个必须处理多个位图并显示它们的应用程序
进入网络视图。如果用户单击按钮,webview 的内容会发生变化。
一切正常,我拿了位图,将它们转换为 Base 64,没问题。
然后我决定稍微更改我的代码以更有条理,现在是 webview
只在第一次显示内容然后 loadData()
什么都不做,即使是参数
html字符串包含一个不同的 HTML。我不明白为什么 webview 不再工作了。
没有来自 chromium 的错误警告,没有异常,我来自 UI 线程
运行 loadData()
这是一些代码:
// Load the pure html content, then calling loadData() with it
CompletableFuture.supplyAsync(htmlProvider::doHTML)
.thenAccept(htmlText ->
runOnUiThread(() -> {webView.loadData(htmlText, "text/html; charset=UTF-8", "UTF-8");
Logger.logV(htmlText);})) // Load data the first time, then do nothing even if html text has changed
.exceptionally(throwable -> {Logger.handleException(throwable); Logger.logV("ERROR"); return null;})
.thenRun(() -> {
Logger.logV("isLoading -> false");
isLoading = false;
});
doHTML()
只需提供一些 html 并负责将位图作为 Base64 加载到其中。
感谢您的帮助
这是loadData(String data, String mimeType, String encoding)
方法的常见问题,
将其替换为
loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl)
我正在开发一个必须处理多个位图并显示它们的应用程序 进入网络视图。如果用户单击按钮,webview 的内容会发生变化。
一切正常,我拿了位图,将它们转换为 Base 64,没问题。
然后我决定稍微更改我的代码以更有条理,现在是 webview
只在第一次显示内容然后 loadData()
什么都不做,即使是参数
html字符串包含一个不同的 HTML。我不明白为什么 webview 不再工作了。
没有来自 chromium 的错误警告,没有异常,我来自 UI 线程
运行loadData()
这是一些代码:
// Load the pure html content, then calling loadData() with it
CompletableFuture.supplyAsync(htmlProvider::doHTML)
.thenAccept(htmlText ->
runOnUiThread(() -> {webView.loadData(htmlText, "text/html; charset=UTF-8", "UTF-8");
Logger.logV(htmlText);})) // Load data the first time, then do nothing even if html text has changed
.exceptionally(throwable -> {Logger.handleException(throwable); Logger.logV("ERROR"); return null;})
.thenRun(() -> {
Logger.logV("isLoading -> false");
isLoading = false;
});
doHTML()
只需提供一些 html 并负责将位图作为 Base64 加载到其中。
感谢您的帮助
这是loadData(String data, String mimeType, String encoding)
方法的常见问题,
将其替换为
loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl)