【发布时间】:2020-09-12 00:17:30
【问题描述】:
所以,如果 WebView 中没有连接,我会向我的应用添加消息,如下所示:
webviewku.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView webView, int errorCode, String description, String failingUrl) {
try {
webView.stopLoading();
} catch (Exception e) {
}
if (webView.canGoBack()) {
webView.goBack();
}
webView.loadUrl("about:blank");
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Error");
alertDialog.setMessage("Anda tidak memiliki koneksi internet. Sambungkan perangkat anda ke internet dan coba lagi.");
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Coba Lagi", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
startActivity(getIntent());
}
});
alertDialog.show();
super.onReceivedError(webView, errorCode, description, failingUrl);
}
});
注意事项: webviewku = 我的 WebView 名称; 警报消息和按钮以印度尼西亚语显示。
无论如何,我使用整个 webview 作为主窗口(我的意思是,我将我的网站转换为应用程序),并且我有很多页面需要下载东西。我正在使用“无 Internet 连接”消息来确保在没有 Internet 连接时不会显示我的网站域并且不会被任何人看到。
所以,我让这个应用程序具有下载文件的能力。但是,由于 webview 不加载任何更改而只下载文件,所以会出现“无互联网连接”消息。
如何使下载文件后不出现此消息?
【问题讨论】:
标签: java android webview connection