0

我正在尝试为使用 webview 的应用程序创建自定义错误消息。到目前为止,我正在使用下面的代码,它有一个非常小的问题......当我点击网页视图上的链接时,页面正在重新加载同一页面,而不是处理点击的链接。我在 webview 上的链接是下载链接,所以它应该使用相同的应用程序下载或打开下载器选项

protected void fetch_web(){
    final WebView web;
    web = (WebView) findViewById(R.id.voice_mail_view_port);
    NoNetwork = (Button) findViewById(R.id.btn_no_internet);
    NoNetwork.setVisibility(View.GONE);
    String mdb = "http://192.168.23.1/default.php";

    getWindow().setFeatureInt(  Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
    final Activity MyActivity = this;
    web.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress)
        {

            MyActivity.setTitle("Fetching feeds...");
            MyActivity.setProgress(progress * 100);

            loader();

            if(progress == 100) {
                MyActivity.setTitle(R.string.app_name);
                deLoader();;
            }
        }
    });
    web.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String
                failingUrl) {
            deLoader();
            alert("No Internet Connection","Let's get connected to see feeds");
            web.setVisibility(View.GONE);
            NoNetwork.setVisibility(View.VISIBLE);
        }
    });
    web.getSettings().setJavaScriptEnabled(true);
    web.loadUrl((mdb));
}
protected  void loader(){
    loading = (ProgressBar) findViewById(R.id.loader);
    loading.setVisibility(View.VISIBLE);
}
protected  void  deLoader(){
    loading = (ProgressBar) findViewById(R.id.loader);
    loading.setVisibility(View.INVISIBLE);
}

示例下载链接http://192.168.23.1/download.php?id=1

有人可以帮我吗,我怀疑我的错误来自这里

web.setWebViewClient(new WebViewClient() {
    public void onReceivedError(WebView view, int errorCode, String description, String
            failingUrl) {
        deLoader();
        alert("No Internet Connection","Let's get connected to see feeds");
        web.setVisibility(View.GONE);
        NoNetwork.setVisibility(View.VISIBLE);
    }
}); 
4

1 回答 1

0

尝试强制应用在其他浏览器中打开链接

Intent intent= new Intent(Intent.ACTION_VIEW,Uri.parse(url));
startActivity(intent);

如果失败,请告诉我以提供更多帮助。

于 2017-02-02T10:35:30.227 回答