0

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))
skushu
  • 311
  • 1
  • 3
  • 11
  • Try adding the destination explicitly in your request by using .setDestinationInExternalPublicDir() or similar. – Deepak Nov 22 '21 at 03:31
  • .setDestinationInExternalPublicDir( Environment.DIRECTORY_DOWNLOADS, "/" + context.getString(R.string.app_name) + "/" + fileName ) – Faizan Haidar Khan Nov 24 '21 at 12:04

0 Answers0