1

I'm working on an application where the user can download files into his device , when i press on the file , it get downloaded and pushed into the directory i created but the issue is that the notification which shows is the file is downloading or not , it is not showing , and i tried but it is not working , if anyone could help me , thank you

  • This is my code
private fun downloadFileIntoDevice(){
       val fileExtension = chatModel.chatItem.substringAfterLast(".")
       val directory = File(Environment.getExternalStorageDirectory().path + "/jobsFolder",
           UUID.randomUUID().toString().substring(0,5) + "." + fileExtension)

       if(!directory.exists()){
           directory.mkdir()
       }

       val downloadRequest = DownloadManager.Request(Uri.parse(chatModel.chatItem.substringBeforeLast(".")))
       downloadRequest.setTitle("الملف")
       downloadRequest.setDescription("تحميل الملف")
       downloadRequest.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI
               or DownloadManager.Request.NETWORK_MOBILE)
       downloadRequest.setDestinationUri(directory.toUri())
       downloadRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
       val downloadID =  downloadManager.enqueue(downloadRequest)
}

PS : I'm already giving permission to download the file in android 11 and below , the file is being saved into directory after download but the download notification not showing.

Taki
  • 3,290
  • 1
  • 16
  • 41
  • Your desrination uri should be for a file. But yours is a directory. – blackapps Aug 24 '21 at 06:17
  • `I'm already giving permission to download the file in android 11 and below` ? What do you mean? For downloading a file you dont need a permission. Which permission are you talking about? – blackapps Aug 24 '21 at 06:19
  • The downloaded file will be stored on the device so you re accessing the device storage , will i need permission to do ? talking about the permission for android 11 and below – Taki Aug 24 '21 at 07:50
  • If you read my post , i said that the file gets downloaded and i could check it in the directory i chose , the problem is that the notification which shows if the file is downloading is not showing , like when you download a file , notification pops up showing for example the progress of the download , hope you understood what i mean , thank you – Taki Aug 24 '21 at 07:52
  • Yes. But i still dont understand about which permission you are talking to download a file. I asked you to tell which permission but you still did not tell. Any reason? And why dont you react on the folder/file ptoblem? – blackapps Aug 24 '21 at 08:08
  • Sorry if there was any misconception , what i meant is the storage permission not a download permission ( i know there is no permission to download file ) , because i didnt include the storage permission code , so i just mentionned it – Taki Aug 24 '21 at 08:15
  • `Your desrination uri should be for a file. But yours is a directory. ` Third time i ask: why dont you react? Any reason? – blackapps Aug 24 '21 at 08:22
  • I'm actually responding , regarding the last question , I found an example where it used it that way , and because the file is getting stored after download I thought that's correct , is it a must to use file for notification to show ? – Taki Aug 24 '21 at 08:38

0 Answers0