title: Webview app: How to download a file inside webview app & external link should open outside the app
body: <p>I want to download specific file inside android webview app ( although they are from external link not from my webview app URL) and all external link should open outside webview app means phone browser.</p>
  
  <p>I used code below to  do that.</p>
  
  <pre><code> wv.setWebViewClient(new WebViewClient(){
  
  
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
  
              boolean value = true;
              String extension = MimeTypeMap.getFileExtensionFromUrl(url);
              if (extension != null) {
                  MimeTypeMap mime = MimeTypeMap.getSingleton();
                  String mimeType = mime.getMimeTypeFromExtension(extension);
                  if (mimeType != null) {
                      if (mimeType.toLowerCase().contains("pdf")
                              || extension.toLowerCase().contains("ppt")
                              || extension.toLowerCase().contains("doc")
                              || extension.toLowerCase().contains("rar")
                              || extension.toLowerCase().contains("rtf")
                              || extension.toLowerCase().contains("exe")
                              || extension.toLowerCase().contains("apk")
                              || extension.toLowerCase().contains("jpeg")
                              || extension.toLowerCase().contains("png")
                              || extension.toLowerCase().contains("xls")
                              || extension.toLowerCase().contains("zip")
                              || extension.toLowerCase().contains("jpg")) {
                          DownloadManager mdDownloadManager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
                          DownloadManager.Request request = new DownloadManager.Request(
                                  Uri.parse(url));
                          String name= URLUtil.guessFileName(url,null,MimeTypeMap.getFileExtensionFromUrl(url));
                          File destinationFile = new File(Environment.getExternalStorageDirectory(),name);
                          request.setDescription("Downloading...");
                          request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                          // request.setDestinationUri(Uri.fromFile(destinationFile));
                          request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,name);
                          mdDownloadManager.enqueue(request);
                          //value = false;
                      }
                  }
                  if (value) {
                      view.loadUrl(url);
                  }
  
                  if (!url.contains("my site url")) { // Could be cleverer and use a regex
                      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                      startActivity(intent);
                      return true;
                  }
                  return false;
              }
              return false;
  
          }   
  
  
          @Override
          public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)  {
              wv.loadUrl(mypage_error);
          }
      }
  </code></pre>
  
  <p>When i click any link containing above extension, the file starting download inside the webview app (It's OK) but at the same time that link automatically opening into my mobile browser. I know this is happening because of this code.</p>
  
  <pre><code>if (!url.contains("my site url")) { // Could be cleverer and use a regex
                      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                      startActivity(intent);
                      return true;
                  }
                  return false;
  </code></pre>
  
  <p>Now, </p>
  
  <p><strong>Firstly Solution</strong>  I want know how can I download files containing above extension inside webview app and all link that don't contain above extension should open outside my webview app that means mobile browser.</p>
  
  <p><strong>Secondly Solution</strong>
  If it is not possible then tell me, when I click the link how to show alert/popup (browser choosing option) every time. As i mentioned instead of showing browser choosing alert links are opening automatically to my phone browser.</p>