在我检查文件之前,在Android上下载的图像未显示
我正在Android Studio中与Kotlin一起制作一个应用程序,其中一个功能是从URL下载图像,并在本地保存。(下载或图片文件夹都很好)
,我似乎无法做到任何意义的问题的:
下载管理器下载图像时,显示图像已完成。 在我的开发应用程序中,当我访问文件时,我可以看到所有其他旧照片,但没有我刚下载的最新照片。
当我离开应用程序,然后在AVD上打开文件或Google照片时,我可以在此处看到新下载的图像。
然后,当我返回我的应用程序并再次打开文件时,现在我可以看到最新的下载图像了???
我不想退出我的应用程序,打开文件应用程序以确保保存图像,然后回到我的应用程序中以使用图像。 kotlin代码获取图像链接并下载
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论