コード例 #1
0
ファイル: DownloadUtil.java プロジェクト: hm17gh1/XCSoar
  static void enumerate(DownloadManager dm, long handler) {
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterByStatus(
        DownloadManager.STATUS_PAUSED
            | DownloadManager.STATUS_PENDING
            | DownloadManager.STATUS_RUNNING);
    Cursor c = dm.query(query);

    if (!c.moveToFirst()) return;

    final int columnLocalURI = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI);
    final int columnStatus = c.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS);
    final int columnSize = c.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES);
    final int columnPosition =
        c.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR);

    do {
      final String uri = c.getString(columnLocalURI);
      final String path = matchPath(uri);
      if (path == null) continue;

      /* strip the "file://" */
      int status = c.getInt(columnStatus);
      long size = c.getLong(columnSize);
      long position = status == DownloadManager.STATUS_RUNNING ? c.getLong(columnPosition) : -1;

      onDownloadAdded(handler, path, size, position);
    } while (c.moveToNext());
  }
コード例 #2
0
ファイル: DownloadUtil.java プロジェクト: ktt9117/MJChurch
  private static boolean isDownloadFailedItem(Context context, SermonItem item) {
    DownloadManager downloadManager =
        (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterByStatus(DownloadManager.STATUS_FAILED);
    Logger.i(TAG, "=========== Download Failed Item Query ==========");
    Cursor c = downloadManager.query(query);
    if (c != null && c.getCount() > 0) {
      boolean loopFlag = true;
      while (c.moveToNext() && loopFlag) {
        String columnUri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_URI));
        Logger.i(TAG, "COLUMN_URI : " + columnUri);
        Logger.i(TAG, "item.audioUrl : " + Const.BASE_URL + item.audioUrl);
        if (columnUri.equals(Const.BASE_URL + item.audioUrl)) {
          // 기존에 있던 파일이 정상적으로 다운로드 되지 않은 파일이므로 삭제
          File file =
              new File(Const.DIR_PUB_DOWNLOAD, item.titleWithDate + StringUtils.FILE_EXTENSION_MP3);
          file.delete();
          return true;
        }
      }
      c.close();
    } else {
      Logger.i(TAG, "cursor is null or count <= 0");
      return false;
    }

    return false;
  }
コード例 #3
0
  private void checkForDownloadingStatus() {
    DownloadManager.Query query = new DownloadManager.Query();
    query =
        query.setFilterByStatus(
            DownloadManager.STATUS_RUNNING
                | DownloadManager.STATUS_PENDING
                | DownloadManager.STATUS_PAUSED
                | DownloadManager.STATUS_FAILED);
    downloadCursor = dm.query(query);
    // do one time for init data
    handler.sendEmptyMessage(EVENT_RELOAD_DOWNLOAD);

    downloadCursor.registerContentObserver(mDownloadObserver);
  }
コード例 #4
0
ファイル: DownloadUtil.java プロジェクト: hm17gh1/XCSoar
  /** Find a download with the specified name. Returns -1 if none was found. */
  static long findPath(DownloadManager dm, String path) {
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterByStatus(
        DownloadManager.STATUS_PAUSED
            | DownloadManager.STATUS_PENDING
            | DownloadManager.STATUS_RUNNING);
    Cursor c = dm.query(query);

    if (!c.moveToFirst()) return -1;

    final int columnID = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
    final int columnLocalURI = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI);

    do {
      final String uri = c.getString(columnLocalURI);
      if (uri != null && uri.endsWith(path)) return c.getLong(columnID);
    } while (c.moveToNext());

    return -1;
  }
コード例 #5
0
ファイル: DownloadUtil.java プロジェクト: hm17gh1/XCSoar
  static void checkComplete(DownloadManager dm) {
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterByStatus(DownloadManager.STATUS_FAILED | DownloadManager.STATUS_SUCCESSFUL);
    Cursor c = dm.query(query);

    if (!c.moveToFirst()) return;

    final int columnLocalURI = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI);
    final int columnId = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
    final int columnStatus = c.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS);

    do {
      final String uri = c.getString(columnLocalURI);
      final String path = matchPath(uri);
      if (path == null) continue;

      final int status = c.getInt(columnStatus);
      final boolean success = status == DownloadManager.STATUS_SUCCESSFUL;
      onDownloadComplete(path, success);

      final long id = c.getLong(columnId);
      dm.remove(id);
    } while (c.moveToNext());
  }