title: How to debug file download WebView code that is causing a corrupted file?
body: <p>I am a newbie in Android app development. I have done this for downloading a documents in my webview.</p>
  
  <p>I want to download the file but it is downloading some corrupted file.  I had added the required permissions in <strong>manifest.xml</strong>.</p>
  
  <pre><code>private class MyWebviewClient extends WebViewClient {
  
      @Override
      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 via Your app name..");
                      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);
              }
          }
          return false;
  
      }
  }
  </code></pre>