private void download(String url) {
    try {
      mFile =
          FileUtil.getDestinationInExternalPublicDir(
              getFileDownloadPath(), mFileObject.getSaveName(mProjectObjectId));

      PersistentCookieStore cookieStore =
          new PersistentCookieStore(AttachmentsDownloadDetailActivity.this);
      String cookieString = "";
      for (Cookie cookie : cookieStore.getCookies()) {
        cookieString += cookie.getName() + "=" + cookie.getValue() + ";";
      }

      DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
      request.addRequestHeader("Cookie", cookieString);
      request.setDestinationInExternalPublicDir(
          getFileDownloadPath(), mFileObject.getSaveName(mProjectObjectId));
      request.setTitle(mFileObject.getName());
      // request.setDescription(mFileObject.name);
      // request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
      request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
      request.setVisibleInDownloadsUi(false);
      // request.allowScanningByMediaScanner();
      // request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
      // request.setShowRunningNotification(false);

      downloadId = downloadManager.enqueue(request);
      downloadListEditor.putLong(mFileObject.file_id, downloadId);
      downloadListEditor.commit();
    } catch (Exception e) {
      Toast.makeText(this, R.string.no_system_download_service, Toast.LENGTH_LONG).show();
    }
  }
  private void bindView() {
    hideProgressDialog();

    icon.setVisibility(View.VISIBLE);
    icon.setImageResource(mFileObject.getIconResourceId());

    iconTxt.setVisibility(View.GONE);

    name.setText(mFileObject.getName());

    content.setText(Global.HumanReadableFilesize(mFileObject.getSize()));

    tvDownload.setText(
        String.format(
            downloadFormat,
            Global.HumanReadableFilesize(0.0),
            Global.HumanReadableFilesize(mFileObject.getSize())));
    progressBar.setMax(mFileObject.getSize());
    mainLayout.setVisibility(View.VISIBLE);

    mFile =
        FileUtil.getDestinationInExternalPublicDir(
            getFileDownloadPath(), mFileObject.getSaveName(mProjectObjectId));
    Log.d(TAG, "downloadId:" + downloadId);

    File file =
        FileUtil.getDestinationInExternalPublicDir(
            getFileDownloadPath(), mAttachmentFileObject.getSaveName(mProjectObjectId));
    if (file.exists() && file.isFile()) {
      showState(STATE_FINISHDOWNLOAD);
    } else {
      showState(STATE_NEEDDOWNLOAD);
    }
  }
  @Override
  public void parseJson(int code, JSONObject response, String tag, int pos, Object data)
      throws JSONException {
    if (tag.equals(urlFiles)) {
      if (code == 0) {
        hideProgressDialog();
        JSONObject file = response.getJSONObject("data").getJSONObject("file");
        mFileObject = new AttachmentFileObject(file);
        downloadId = downloadList.getLong(mFileObject.file_id, 0L);

        icon.setVisibility(View.VISIBLE);
        icon.setImageResource(mFileObject.getIconResourceId());

        iconTxt.setVisibility(View.GONE);

        name.setText(mFileObject.name);

        content.setText(Global.HumanReadableFilesize(mFileObject.size));

        tvDownload.setText(
            String.format(
                downloadFormat,
                Global.HumanReadableFilesize(0.0),
                Global.HumanReadableFilesize(mFileObject.size)));
        progressBar.setMax(mFileObject.size);
        mainLayout.setVisibility(View.VISIBLE);

        mFile = FileUtil.getDestinationInExternalPublicDir(getFileDownloadPath(), mFileObject.name);
        Log.d(TAG, "downloadId:" + downloadId);
        if (mFile.exists() && mFile.isFile() && mFile.length() == mFileObject.size) {
          Log.d(TAG, "mFile exists:");
          if (downloadId != 0L) {
            updateView();
          }
          showState(STATE_FINISHDOWNLOAD);
        } else {
          Log.d(TAG, "mFile not exists:");
          showState(STATE_NEEDDOWNLOAD);
        }

      } else {
        hideProgressDialog();
        showErrorMsg(code, response);
      }
    } else if (tag.equals(HOST_FILE_DELETE)) {
      if (code == 0) {
        hideProgressDialog();
        showButtomToast("删除完成");
        Intent resultIntent = new Intent();
        resultIntent.putExtra("mAttachmentFileObject", mAttachmentFileObject);
        setResult(RESULT_OK, resultIntent);
        finish();
      } else {
        showErrorMsg(code, response);
      }
    }
  }
  @AfterViews
  protected final void initAttachmentsDownloadDetailActivity() {
    share =
        AttachmentsDownloadDetailActivity.this.getSharedPreferences(
            FileUtil.DOWNLOAD_SETTING, Context.MODE_PRIVATE);
    defaultPath = Environment.DIRECTORY_DOWNLOADS + File.separator + FileUtil.DOWNLOAD_FOLDER;
    mFileObject = mAttachmentFileObject;

    if (mAttachmentFileObject != null) {
      File file =
          FileUtil.getDestinationInExternalPublicDir(
              getFileDownloadPath(), mAttachmentFileObject.getSaveName(mProjectObjectId));
      if (file.exists() && file.isFile()) {
        jumpTextHtmlActivity();
        showState(STATE_FINISHDOWNLOAD);
      }
    }

    getSupportActionBar().setTitle(mAttachmentFileObject.getName());
    handler = new MyHandler();
    downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    downloadManagerPro = new DownloadManagerPro(downloadManager);

    completeReceiver = new CompleteReceiver();
    registerReceiver(completeReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

    downloadList =
        AttachmentsDownloadDetailActivity.this.getSharedPreferences(
            FileUtil.DOWNLOAD_LIST, Context.MODE_PRIVATE);
    downloadListEditor = downloadList.edit();

    client = MyAsyncHttpClient.createClient(AttachmentsDownloadDetailActivity.this);

    //        urlPages = String.format(urlFiles, mProjectObjectId, mAttachmentFileObject.file_id,
    // mAttachmentFolderObject.file_id);
    urlFiles = String.format(urlFiles, mProjectObjectId, mAttachmentFileObject.file_id);
    urlDownload = String.format(urlDownload, mProjectObjectId, mAttachmentFileObject.file_id);
    if (mAttachmentFileObject == null) {
      mainLayout.setVisibility(View.GONE);
      showDialogLoading();
      getFileUrlFromNetwork();
    } else {
      bindView();
    }

    if (mHideHistoryLayout) {
      layout_dynamic_history.setVisibility(View.INVISIBLE);
    }
  }