DownloadManager队列 - 开始时间

时间:2016-10-03 16:31:34

标签: android download android-download-manager

我有一个应用程序,允许人们更新自己的应用程序。它使用下载管理器并使用“DownloadManager”队列。问题是我想监控下载开始和结束的时间(下载持续的时间)。

我有一个接收器来检查下载何时结束,但我怎么知道它何时开始,因为它在队列中?

如果我知道他的时间到达队列时,我可以开始计算时间。

对此可能有什么解决方案?

1 个答案:

答案 0 :(得分:1)

您可能需要查询DownloadManager以获取更新:

DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(downloadId);
  // downloadId is returned to you upon DownloadManager.enqueue

Cursor cursor = downloadManager.query(query);
if (cursor != null && cursor.moveToFirst()) {
    try {
        int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
        // Decide what to do with it
        // Status are defined as constants in DownloadManager.STATUS_*
    } finally {
        cursor.close();
    }
}