Commit a34f8210 authored by Nihar Thakkar's avatar Nihar Thakkar
Browse files

Check download status when download is complete

parent a04771b0
......@@ -121,7 +121,26 @@ class Downloader(private val applicationInfo: ApplicationInfo, private val fullD
private var onComplete: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
unregisterReceivers(context)
downloaderInterface.onDownloadComplete(context, DownloadManager.STATUS_SUCCESSFUL)
val status = getDownloadStatus()
if (status != null && status == DownloadManager.STATUS_SUCCESSFUL) {
downloaderInterface.onDownloadComplete(context, DownloadManager.STATUS_SUCCESSFUL)
} else {
downloaderInterface.onDownloadComplete(context, DownloadManager.STATUS_FAILED)
}
}
}
private fun getDownloadStatus(): Int? {
val query = DownloadManager.Query().apply {
setFilterById(downloadId)
}
val cursor = downloadManager.query(query)
if (cursor.moveToNext()) {
val columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)
val status = cursor.getInt(columnIndex)
cursor.close()
return status
}
return null
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment