STATUS_PAUSED不会在DownloadManager中调用onReceive()

时间:2016-09-28 07:19:05

标签: android android-download-manager

我使用DownloadManager从服务器下载文件,我预计当网络未连接到互联网时,我会在STATUS_PAUSED中收到BroadcastReceiver。但它并没有打电话给onReceive()

downloadReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
       // ...
    }
}

registerReceiver(downloadReceiver,
    new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

2 个答案:

答案 0 :(得分:0)

您正在对ACTION_DOWNLOAD_COMPLETE操作进行过滤,您的接收方将不会收到任何其他广播。

此外,STATUS_PAUSED不是广播。

它是DownloadManager管理的特定下载的状态,您可以查询。

例如:

DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Query query = new DownloadManager.Query();

query.setFilterById(idsToQuery);
query.setFilterByStatus(DownloadManager.STATUS_PAUSED);

Cursor cursor = dm.query(query);

if (cursor.moveToFirst()) {
    // do whatever you would like with the result
}

答案 1 :(得分:0)

Download Manager类而言,它不会Broadcast关于下载内容状态的任何状态。只播放两种状态

  1. ACTION_DOWNLOAD_COMPLETE

  2. ACTION_NOTIFICATION_CLICKED