Handle download cancelling from outside the app
A download can be cancelled from outside the apps as well using the
Downloads app or the cancel button on the download notification. This
commit handles the case when download is cancelled from outside the app.
@@ -52,7 +52,14 @@ public class DownloadCompleteReceiver extends RoboBroadcastReceiver {
if (nm == null || nm.status != DownloadManager.STATUS_SUCCESSFUL) {
logger.debug("Download seems failed or cancelled for id : " + id);
+ final VideoModel downloadEntry = environment.getDatabase().getDownloadEntryByDmId(id, null);
+ if (downloadEntry != null) {
+ // This means that the download was either cancelled from the native
+ // download manager app or the cancel button on download notification
+ environment.getStorage().removeDownload(downloadEntry);
+ } else {
environment.getDownloadManager().removeDownloads(id);
+ }
return;
} else {
logger.debug("Download successful for id : " + id);
