I have a list of records which I am getting from the ApiAPI call, on the each item of that list I have a file name with other data . That file name is something like f354jklja.png or kioad87943kjkjd.pdf. I am using that list on the recyclerviewrecyclerview, in the each recyclerviewrecyclerview item I have a icon , what I want to do is on the click of that icon corospondingcorresponding file will be download on the phone storage. How can iI do that I am not getting any proper idea. AnyoneCan anyone please help me to solve this.?
thisThis is the function what will trigertrigger on the click of the recyclerviewrecyclerview item:
fun downloadFile(fileUrl: String, fileName: String) { val request = DownloadManager.Request(Uri.parse(fileUrl)) .setTitle(fileName) .setDescription("Downloading") .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName) val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager downloadManager.enqueue(request) } downloadFile function . Using this code the file is not downloading in my phone storage. Using this code the file is not downloading in my phone storage.