【问题标题】:How to make app not showing "No Internet Connection" message after downloading file in WebView?在 WebView 中下载文件后如何使应用程序不显示“无 Internet 连接”消息?
【发布时间】: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


    【解决方案1】:

    一旦完成关闭警报对话框,您可以跟踪文件的下载 在...的帮助下 alertDialog.dismiss();

    【讨论】:

    • 感谢您的评论,但实际上不起作用,对不起。
    • @Jordandreas 我已经编辑了我的评论,请检查。
    • 谢谢你。好吧,我需要一点帮助,我完全是这个 Android Studio 的新手。 alertDialog和下载代码在不同的webView标题中,alertDialogwebviewku.setWebViewClient(new WebViewClient()),下载代码在webviewku.setDownloadListener(new DownloadListener()),这意味着这两个代码不在同一个字段中,我不能只需在webviewku.setDownloadListener(new DownloadListener()) 下方写上alertDialog.dismiss();。所以我该怎么做?对不起,真的很抱歉,我完全是新手:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多