コード例 #1
0
  @Override
  public void setData(AppInfo mData) {
    // 设置数据时,恢复原来的下载状态
    mDownloadManager = DownloadManager.getInstance();
    DownloadInfo downloadInfo = mDownloadManager.getDownloadInfo(mData);
    if (downloadInfo != null) {
      currentState = downloadInfo.getCurrentState();
      progress = downloadInfo.getProgress();
    } else {
      currentState = DownloadManager.STATE_NONE;
      progress = 0;
    }

    super.setData(mData);
  }
コード例 #2
0
 @OnClick({R.id.btn_download, R.id.fl_progress})
 public void click() {
   //        Snackbar.make(getRootView(), "click download", Snackbar.LENGTH_SHORT).show();
   if (currentState == DownloadManager.STATE_NONE
       || currentState == DownloadManager.STATE_ERROR
       || currentState == DownloadManager.STATE_PAUSE) {
     // 开始下载(包含了断点续传)
     mDownloadManager.download(appInfo);
   } else if (currentState == DownloadManager.STATE_DOWNLOADING
       || currentState == DownloadManager.STATE_WAITING) {
     // 在下载的时候,暂停逻辑触发
     mDownloadManager.pause(appInfo);
   } else if (currentState == DownloadManager.STATE_DOWNLOADED) {
     // 下载完成状态点击按钮,需要安装
     mDownloadManager.install(appInfo);
   }
 }
コード例 #3
0
 public void registerObserver() {
   // 下载管理者对象,对现有应用下载过程观察
   mDownloadManager.registerObserver(this);
 }