title: Android download manager completed
body: <p>Small question about the download manager in android.
  It's the first time I'm working with it and have successfully downloaded multiple files and opened them. But my question is how do i check if the download completed.</p>
  
  <p>The situation is I download a PDF file and open it, and usually the file is so small it complets before opening. But if the file is somewhat bigger how do I check if the download manager is finished with the download before opening it.</p>
  
  <p>How I download: </p>
  
  <pre><code>Intent intent = getIntent();
  DownloadManager downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
  Uri Download_Uri = Uri.parse(intent.getStringExtra("Document_href"));
  DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
  
  //Restrict the types of networks over which this download may proceed.
  request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
  //Set whether this download may proceed over a roaming connection.
  request.setAllowedOverRoaming(false);
  //Set the title of this download, to be displayed in notifications.
  request.setTitle(intent.getStringExtra("Document_title"));
  //Set the local destination for the downloaded file to a path within the application's external files directory
  request.setDestinationInExternalFilesDir(this,Environment.DIRECTORY_DOWNLOADS,intent.getStringExtra("Document_title") + ".pdf");
  //Enqueue a new download and same the referenceId
  Long downloadReference = downloadManager.enqueue(request);
  </code></pre>
  
  <p>How I open the file</p>
  
  <pre><code>Uri uri = Uri.parse("content://com.app.applicationname/" + "/Download/" + intent.getStringExtra("Document_title") + ".pdf");
  Intent target = new Intent(Intent.ACTION_VIEW);
  target.setDataAndType(uri, "application/pdf");
  target.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  
  startActivity(target);
  </code></pre>
  
  <p>So somewhere between downloading and opening the file I want a if statement to check if it should continue or wait for the file.</p>