0

I want to use DownloadManager to download file from url in editText. But when I click download button, it will create 2 files with view.filename.text.toString() name in download directory and create other one in TTT directory in download folder with view.filename.text.toString() + "AFK" name.

    view.downloadBTN.setOnClickListener { _ ->
        downloadManager = activity?.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
        request = DownloadManager.Request(Uri.parse(view.uriEDT.text.toString()))
        Log.d("URI", Uri.parse(view.uriEDT.text.toString()).toString())
        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE or DownloadManager.Request.NETWORK_WIFI)
        request.setAllowedOverRoaming(false)
        request.setTitle(view.filename.text.toString())
        request.setDescription("No Description")
        request.setVisibleInDownloadsUi(true)
        Log.d("PATH", Environment.getExternalStoragePublicDirectory(
                DIRECTORY_DOWNLOADS).toString() )
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS + "/TTT/", view.filename.text.toString() + "AFK")
        val refID = downloadManager.enqueue(request)
        //cxt.registerReceiver(onComplete, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
        //list.add(refID)
    }
Hello World
  • 740
  • 5
  • 18

1 Answers1

0

I think this is a generic bug and i guess it doesn't fix yet. Maybe you can use open source libraries for this feature. Many successful library there is in the Github.

Or you can check the link below, it maybe a workaround fix.

https://stackoverflow.com/a/29338184/4355923

volkanhotur
  • 3
  • 1
  • 4