BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
long downloadId = intent.getLongExtra(
DownloadManager.EXTRA_DOWNLOAD_ID, 0);
Query query = new Query();
query.setFilterById(enqueue);
Cursor c = dm.query(query);
if (c.moveToFirst()) {
int columnIndex = c
.getColumnIndex(DownloadManager.COLUMN_STATUS);
context.unregisterReceiver( this );
if (DownloadManager.STATUS_SUCCESSFUL == c
.getInt(columnIndex)) {
Toast.makeText(mContext,
"download complete ",
Toast.LENGTH_SHORT).show();
}
}
}
}
};
DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)for underccessable
toast会因下载失败而被执行。我需要单独获取不成功下载的状态