title: How to use Android Download Manager to download PDF generated from link, not direct PDF file path
body: <p>I have created webview of my website in android app.
  I am using Download Manager in Android to download a PDF file from my website. But there is not a direct link of PDF file, instead that PDF file is getting Generated and because of that thing, I am not able to download that file. Download is showing Unsuccessful. </p>
  
  <p><strong>My Coding:</strong></p>
  
  <pre><code> myWebView.setDownloadListener(new DownloadListener() {
                  @Override
                  public void onDownloadStart(String url, String userAgent,
                                              String contentDisposition, String mimetype,
                                              long contentLength) {
                      try{
                      DownloadManager.Request request = new DownloadManager.Request(
                              Uri.parse(url));
  
                      if(isExternalStorageWritable() &amp;&amp; isExternalStorageReadable()) {
                          request.setTitle("Invoice");
                          request.setDescription("Downloads");
                          request.setVisibleInDownloadsUi(true);
                          request.allowScanningByMediaScanner();
                          request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
                          request.setDestinationInExternalFilesDir(MainActivity.this,Environment.DIRECTORY_DOWNLOADS, "invoice.pdf");//download to internal memory
  
                          DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                          dm.enqueue(request);
                          Toast.makeText(getApplicationContext(), "Downloading File", //To notify the Client that the file is being downloaded
                                  Toast.LENGTH_LONG).show();
                      }
                      else {
                          Toast.makeText(getApplicationContext(), "No SD Card Present.."+Environment.DIRECTORY_DOWNLOADS, //To notify the Client that the file is being downloaded
                                  Toast.LENGTH_LONG).show();
                      }
  
                      }
                      catch (Exception e)
                      {
                          Log.d("Caught inside uri", e.toString());
                      }
                  }
              });// checks for downloads
  </code></pre>