2017-02-02 6 views
0

J'essaie de créer un message d'erreur personnalisé pour mon application qui utilise webview. jusqu'à présent j'utilise le code ci-dessous qui a un problème très minime ... quand je clique sur les liens sur le webview la page recharge la même page au lieu de traiter le lien cliqué. mes liens sur WebView sont le lien de téléchargement non plus il faut télécharger en utilisant la même application ou ouvrir les options vers le bas-chargeurComment afficher le message d'erreur personnalisé sur le 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); 
} 

lien de téléchargement Exemple http://192.168.23.1/download.php?id=1

que quelqu'un peut me aider, je pense mon erreur vient ici

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); 
    } 
}); 

Répondre

0

Essayez de forcer l'application à ouvrir les liens dans d'autres navigateurs

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

Si elle échoue laissez-moi savoir pour aider plus.

+0

A travaillé parfait. Merci – LazyLoading