title: PDF file download problem with android downloadlisteners
body: <p>I can Download all by adding following code in my webview android App. But I can't download pdf file specially from <a href="http://www.garmentsmis.com/Efficiency_Calculator.aspx" rel="nofollow noreferrer">http://www.garmentsmis.com/Efficiency_Calculator.aspx</a>. When i click download it crash App.</p>
  <pre><code>//Runtime External storage permission for saving download files
          if (android.os.Build.VERSION.SDK_INT &gt;= android.os.Build.VERSION_CODES.M) {
              if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                      == PackageManager.PERMISSION_DENIED) {
                  Log.d(&quot;permission&quot;, &quot;permission denied to WRITE_EXTERNAL_STORAGE - requesting it&quot;);
                  String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
                  requestPermissions(permissions, 1);
              }
          }
  
  
  
  
          //handle downloading
          web_view.setDownloadListener(new DownloadListener()
          {
              @Override
              public void onDownloadStart(String url, String userAgent,
                                          String contentDisposition, String mimeType,
                                          long contentLength) {
                  DownloadManager.Request request = new DownloadManager.Request(
                          Uri.parse(url));
                  request.setMimeType(mimeType);
                  String cookies = CookieManager.getInstance().getCookie(url);
                  request.addRequestHeader(&quot;cookie&quot;, cookies);
                  request.addRequestHeader(&quot;User-Agent&quot;, userAgent);
                  request.setDescription(&quot;Downloading File...&quot;);
                  request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType));
                  request.allowScanningByMediaScanner();
                  request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                  request.setDestinationInExternalPublicDir(
                          Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(
                                  url, contentDisposition, mimeType));
                  DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                  dm.enqueue(request);
                  Toast.makeText(getApplicationContext(), &quot;Downloading File. Go to Download folder from File Manager.&quot;, Toast.LENGTH_LONG).show();
              }});
  </code></pre>
  <p>Can anybody explaine me what i need to do? Thanks.</p>