我已经编写了一个代码来使用DownloadManager
来下载某些文件。现在我想做以下事情:
DownloadManager
通知栏内和Google Play内部当前页面中)答案 0 :(得分:6)
要在下载完成时收到通知,请注册接收方以接收ACTION_DOWNLOAD_COMPLETE
广播。它将包含一个EXTRA_DOWNLOAD_ID
额外包含
已完成下载的参考ID。
IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
long reference = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
if (myDownloadReference == reference) {
// Do something with downloaded file.
}
}
};
registerReceiver(receiver, filter);