cshenfu
2024-12-06 12453df3af1e251f92c38f78aeb7f7e211f4432e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.shsening.autouploadvideos.utils
 
import android.app.DownloadManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.widget.Toast
 
class DownloadReceiver(private val context: Context,private val downloadHelper: DownloadHelper) : BroadcastReceiver() {
 
    init {
        context.registerReceiver(this, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
    }
    override fun onReceive(context: Context, intent: Intent) {
        val action = intent.action
        if (DownloadManager.ACTION_DOWNLOAD_COMPLETE == action) {
            val downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
            if (downloadId != -1L) {
                // downoad finished
            }
        }
    }
 
    fun unregister() {
        context.unregisterReceiver(this)
    }
}