2017-02-02 106 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

相關問題