public void initiateDownload() throws Exception {
  String filename=DOWNLOAD_5MB_FILENAME;
  mContext.deleteFile(DOWNLOAD_STARTED_FLAG);
  FileOutputStream fileOutput=mContext.openFileOutput(DOWNLOAD_STARTED_FLAG,0);
  DataOutputStream outputFile=null;
  doCommonDownloadSetup();
  try {
    long dlRequest=-1;
    removeAllCurrentDownloads();
    Uri remoteUri=getExternalFileUri(filename);
    Request request=new Request(remoteUri);
    dlRequest=mDownloadManager.enqueue(request);
    waitForDownloadToStart(dlRequest);
    assertTrue(dlRequest != -1);
    outputFile=new DataOutputStream(fileOutput);
    outputFile.writeLong(dlRequest);
  }
  finally {
    if (outputFile != null) {
      outputFile.flush();
      outputFile.close();
    }
  }
}

public void initiateDownload ( ) throws Exception { String filename = DOWNLOAD_5MB_FILENAME ; mContext . deleteFile ( DOWNLOAD_STARTED_FLAG ) ; FileOutputStream fileOutput = mContext . openFileOutput ( DOWNLOAD_STARTED_FLAG , 0 ) ; DataOutputStream outputFile = null ; doCommonDownloadSetup ( ) ; try { long dlRequest = - 1 ; removeAllCurrentDownloads ( ) ; Uri remoteUri = getExternalFileUri ( filename ) ; Request request = new Request ( remoteUri ) ; dlRequest = mDownloadManager . enqueue ( request ) ; waitForDownloadToStart ( dlRequest ) ; assertTrue ( dlRequest != - 1 ) ; outputFile = new DataOutputStream ( fileOutput ) ; outputFile . writeLong ( dlRequest ) ; } finally { if ( outputFile != null ) { outputFile . flush ( ) ; outputFile . close ( ) ; } } }
initiates a download . queues up a download to the download manager , and saves the downloadmanager ' s assigned download id for this download to a file .
