title: Cancelling Dropbox getFile download
body: <p>When using the Android Dropbox SDK, does anyone know of the best way to cancel a download after the getFile call starts. At the moment, my AsyncTask class does the following:</p>
  
  <pre><code>@Override
  protected O2ShellFileManagerError doInBackground(File... params) {
      if (params[0] == null) {
          return new O2ShellFileManagerError(
                  "No File found.",
                  O2ShellErrorCode._o2sfm_ec_unknown);
      }
  
      File mFile = params[0];
  
      try {
          DropboxAPI&lt;AndroidAuthSession&gt; mDBApi = O2DropboxStorage
                  .getDropboxSession(mContext);
  
          // mOutputStream is class level field.
          mOutputStream = new FileOutputStream(mFile);
          DropboxFileInfo info = mDBApi.getFile(mDropboxPath, null,
                  mOutputStream, new ProgressListener() {
  
                      @Override
                      public void onProgress(long bytes, long total) {
                          if (!isCancelled())
                              publishProgress(bytes, total);
                          else {
                              if (mOutputStream != null) {
                                  try {
                                      mOutputStream.close();
                                  } catch (IOException e) {
                                  }
                              }
                          }
                      }
                  });
      } catch (DropboxException e) {
          Log.e("DbExampleLog",
                  "Something went wrong while getting file.");
  
      } catch (FileNotFoundException e) {
          Log.e("DbExampleLog", "File not found.");
  
      } finally {
          if (mOutputStream != null) {
              try {
                  mOutputStream.close();
                  mOutputStream = null;
              } catch (IOException e) {
              }
          }
      }
      /*
       * The task succeeded
       */
      return null;
  }
  </code></pre>
  
  <p>So my workaround above essentially closes the mOutputStream in the OnProgess method which generates the DropboxException. Is there a better / cleaner way than this?</p>