public void download(
      Context context, String url, String path, long apkSize, DownloadProgressListener listener) {
    try {
      // 开始时间,放在循环外,求解的usedTime就是总时间
      long startTime = System.currentTimeMillis();
      isDownFinish = false; // 下载未完成
      singleDownloadThread = new SingleDownloadThread(context, url, path, listener);
      singleDownloadThread.setPriority(7);
      singleDownloadThread.start();
      while (!isDownFinish) { // 循环判断所有线程是否完成下载
        Thread.sleep(50);
        isDownFinish = false; // 假定全部线程下载完成
        isError = false;
        // 如果下载线程为空 或者 下载线程标识为下载完成但是下载进度却是-1,重新下载
        if (singleDownloadThread == null
            || (singleDownloadThread.isFinish() && singleDownloadThread.getDownSize() == -1)) {
          isDownFinish = false; // 设置标志为下载没有完成
          isError = true;
          //                    Log.d("SingleThreadDownloader", "下载失败,重新开启一条线程");

          // 如果下载失败,再重新下载
          singleDownloadThread = new SingleDownloadThread(context, url, path, listener);
          singleDownloadThread.setPriority(7);
          singleDownloadThread.start();
        }

        if (singleDownloadThread != null && singleDownloadThread.isFinish()) {
          isDownFinish = true;
        }
        countDownProgress(listener, startTime, apkSize);
      }

      if (listener != null && isCancel) {
        // 如果结束下载的时候,下载百分比小于100,认为是取消下载
        listener.onDownCancel("");
        return;
      }
      if (listener != null) {
        countDownProgress(listener, startTime, apkSize);
        listener.onDownloadFinish("", path);
      }
    } catch (Exception e) {
      if (listener != null) {
        listener.onDownFailed("", e.getMessage());
      }
    }
  }