title: Downloading a PDF file with DownloadManager
body: <p>I'm trying to download a PDF file from a server.</p>
  
  <p>External storage is saved:</p>
  
  <blockquote>
    <p>static final File fSdcard = new
    File(Environment.getExternalStorageDirectory().toString(), "VDTEC");</p>
  </blockquote>
  
  <p>Name of file:</p>
  
  <blockquote>
    <p>static final File fManualMult = new File(fSdcard, "ManualMult.pdf");</p>
  </blockquote>
  
  <p>The Download ID</p>
  
  <blockquote>
    <p>private long lDownloadID;</p>
  </blockquote>
  
  <p>And the URL:</p>
  
  <blockquote>
    <p>static final String sUrlManualMult = "<a href="http://germipasto.com.br/comunicacao/app/MULT/MANUAL%20VD%20TEC%20MULT%20-%20revis%C3%A3o%2001%20-%2002-fev%202018.pdf" rel="nofollow noreferrer">http://germipasto.com.br/comunicacao/app/MULT/MANUAL%20VD%20TEC%20MULT%20-%20revis%C3%A3o%2001%20-%2002-fev%202018.pdf</a>";</p>
  </blockquote>
  
  <p>When I press the button, the "beginDownload" method is called:</p>
  
  <blockquote>
    <p>private void beginDownload(){</p>
  
  <pre><code>    /*
      Create a DownloadManager.Request with all the information necessary to start the download
       */
  
      DownloadManager.Request request=new DownloadManager.Request(Uri.parse(sUrlManualMult))
              .setMimeType("application/pdf")
              .setTitle("Dummy File")// Title of the Download Notification
              .setDescription("Downloading")// Description of the Download Notification
              .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)// Visibility of the download Notification
              .setDestinationUri(Uri.fromFile(fManualMult))// Uri of the destination file
              .setRequiresCharging(false)// Set if charging is required to begin the download
              .setAllowedOverMetered(true)// Set if download is allowed on Mobile network
              .setAllowedOverRoaming(true);// Set if download is allowed on roaming network
      request.allowScanningByMediaScanner();
      DownloadManager downloadManager= (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
      lDownloadID = downloadManager.enqueue(request);// enqueue puts the download request in the queue.
  }
  </code></pre>
  </blockquote>
  
  <p>I also have a broadcaster that shows a toast when the download is completed:</p>
  
  <blockquote>
    <p>private BroadcastReceiver onDownloadComplete = new BroadcastReceiver()
    {</p>
  
  <pre><code>    @Override
      public void onReceive(Context context, Intent intent) {
          //Fetching the download id received with the broadcast
          long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
          //Checking if the received broadcast is for our enqueued download by matching download id
          if (lDownloadID == id) {
              Toast.makeText(DocumentosActivity.this, "Download Completed", Toast.LENGTH_SHORT).show();
          }
      }
  };
  </code></pre>
  </blockquote>
  
  <p>And register it:</p>
  
  <blockquote>
    <p>registerReceiver(onDownloadComplete,new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));</p>
  </blockquote>
  
  <p>The problem is:
  When I click, the Toast is shown in 1-2 sec and the download is not completed.
  What am I doing wrong?</p>
  
  <p>PS: I have found that if a change the link (ex: using <a href="http://speedtest.ftp.otenet.gr/files/test10Mb.db" rel="nofollow noreferrer">http://speedtest.ftp.otenet.gr/files/test10Mb.db</a> directly) the downloadmanager works.
  Could be an error with my link?
  I uploaded the file via ftp and it can be accessed via browser.</p>