0

I have audio 'url' "https://my-server.com/555.mp3"

how can I download it to "externalCacheDir" to be easy access without internet

i tried to use DownloadManager but i think there is better way to do it

    fun downloadAudio(url:String){
        val request = DownloadManager.Request(url.toUri())
        val externalCachPath = getApplication<Application>().externalCacheDir!!.absolutePath
        val fileName = "${UUID.randomUUID()}.3gp"
        request.setDestinationInExternalPublicDir(externalCachPath,fileName)

        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
        request.setDescription("Download")

        request.setTitle(fileName)

        download(request)

        return filename
        
    }

Omar Khaled
  • 439
  • 1
  • 4
  • 16

0 Answers0