【发布时间】:2017-05-29 08:45:33
【问题描述】:
当文件开始下载时,我会显示进度条,如果完成,我会使用成功下载图标更改进度条。它工作得很好,但我面临的问题是,如果有人点击通知托盘中的取消按钮,它不会发送我创建的广播,以便在文件下载时接收广播。
我正在使用 DownloadManager 下载文件,正如我们在 marshmallow 中所知道的,我们可以选择下载文件,但如何捕获此取消按钮的事件。
这是我的代码:
<receiver android:name=".adapters.VideoListAdapter$VideoDownloadedReceiver">
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
<action android:name="android.intent.action.DOWNLOAD_CANCEL" />
</intent-filter>
</receiver>
public static class VideoDownloadedReceiver extends BroadcastReceiver implements AsyncResponse {
@Override
public void onReceive(Context context, Intent intent) {
//perform event
//works well if files gets completed but not if download gets cancel
}
}
【问题讨论】:
标签: android android-6.0-marshmallow android-broadcast android-download-manager android-broadcastreceiver