2017-02-02 87 views
0

我正尝试为使用webview的应用程序创建自定义错误消息。到目前为止,我使用下面的代码有一个非常小的问题...当我点击webview上的链接页面重新加载相同的页面,而不是处理点击链接。我的web视图链接下载链接,要么应该下载使用相同的应用程序或打开向下加载程序选项如何在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); 
    } 
}); 

回答

0

尝试强制应用在其他浏览器

打开链接
Intent intent= new Intent(Intent.ACTION_VIEW,Uri.parse(url)); 
startActivity(intent); 

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

+0

工作完美。谢谢 – LazyLoading

相关问题