What I'm trying to do is have a basic pdf downloaded whenever I press a button. When I press the button I'm getting the text indicator "done" but nothing is being downloaded
btn_download.setOnClickListener {
var downloadRequest = DownloadManager.Request(
Uri.parse ("http://www.africau.edu/images/default/sample.pdf"))
.setTitle("a pdf")
.setDescription("a pdf")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
//over data
.setAllowedOverMetered(true)
.setAllowedOverRoaming(true)
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
downloadID = downloadManager.enqueue(downloadRequest)
}
var receiver = object:BroadcastReceiver(){
override fun onReceive(context: Context?, intent: Intent?) {
var id= intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
if (downloadID == id){
Toast.makeText(applicationContext, "done",Toast.LENGTH_LONG).show()
}
}
}
registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))