如何在webview

时间:2017-02-02 02:19:07

标签: java webview custom-error-handling

我正在尝试为使用webview的应用创建自定义错误消息。到目前为止,我使用下面的代码有一个非常小的问题...当我点击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);
    }
}); 

1 个答案:

答案 0 :(得分:0)

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

private void PrintButton_Click(object sender, RoutedEventArgs e)
{
    // Use the wrapper to get the Visual objects to be printed.
    UIElement content = printContent.GetPrintContent();
    Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(delegate()
    {
        // Works fine now.
        FixedPage page = new FixedPage();
        page.Children.Add(content as UIElement);
        var command = ((sender as Button).DataContext as ICommand);
        command.Execute(page);
    }));
}

如果失败,请让我知道更多帮助。