'Downloaded image on Android not showing up before i check files
i am making an app with Kotlin in Android Studio, where a feature is to download an image from an URL, and save it locally.(Either downloads or pictures folder is fine)
The issue that came, that i cant seem to make any sense of:
When i download an image, the download manager, shows the image is complete. In my dev app, when i access files, i can see all my other old photos, but not the newest one i just downloaded.
When i go out of my app, and open either files or Google photos on the AVD, i can see the newely downloaded image pop up here.
Then, when i go back to my app, and open files again, NOW i can see the newest downloaded image???
I dont want to have to exit my app, open files app to make sure the image got saved, then go back into my app to use the image. Kotlin code that takes an image link, and downloads it
val imgName = imgLink?.substring(imgLink?.lastIndexOf("/") + 1)
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val request = DownloadManager.Request(downloadUri).apply {
setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI or DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setAllowedOverMetered(true)
.setTitle("$imgName.png")
.setDescription("")
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "$imgName.png")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
}
downloadManager.enqueue(request)
```
Also, when i click the downloaded image from my notifications, it just shows an black square with a spinning circle ( even tho it says download finnished) and it still shows up normally in the google photos and files app.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
