Below is my code which i integrated to download the video(.mp4) functionality. This code is working in my Android 8 device. The same code is not working in latest Android version. May be i am missing something or is there any deprecation issue?
val dm = getSystemService(DOWNLOAD_SERVICE) as DownloadManager
val url =
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"
val request = DownloadManager.Request(
Uri.parse(url)
)
fileName = url.substring(url.lastIndexOf('/') + 1)
fileName =
fileName.substring(0, 1).uppercase(Locale.getDefault()) + fileName.substring(1)
request.setDestinationInExternalFilesDir(
this,
Environment.DIRECTORY_DOWNLOADS,
fileName
)
enqueue = dm?.enqueue(request)!!
I tried debugging, looked for if there is any issue regarding the URL but there aren't any and also tried for the error logs but there aren't any error for the same.