下载Manger无法在Android中下载大文件
通过大文件,我的意思是8.5 MB和小文件,是指80kb至1MB。
虽然下载管理器可以下载最多2GB
的文件
但以下代码可以下载小文件,但不能下载大文件。对于大文件,它显示了下载通知,但是一段时间后,该通知中显示了0KB/未知(等待重试)。在logcat中,没有错误或任何形式的消息可以指向此问题。我正在从普通服务()类调用此代码。
if (PermissionsUtil.hasExternalStoragePermission(context)) {
if (fileName.isNotBlank() && mimeType.isNotBlank()) {
// get download service and enqueue file
Toaster.showMessageShort(R.string.download_started)
manager?.let {
enq = it.enqueue(getDownloadManagerRequest(link, mimeType, fileName, withHeader))
context.registerReceiver(downloadCompletionReceiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
}
}
}
PS:
我能够使用提供给下载管理器的相同URL下载邮递员中的大文件。
我的网络工作正常,我已经在不同的网络上尝试使用6个不同的手机,所有这些都显示出相同的行为。
在下载(大)文件时尝试听所有事件时,我将获得以下活动
paused_waiting_to_retry
更新
所以我尝试了这些这些测试各种不同尺寸的PDF文件(100MB至1GB) ,他们正在下载没有任何问题。但是8.5MB的URL IM进入API响应正在显示paused_waiting_to_retry消息。
而且我还注意到了一件事,当我在Postman中测试1GB文件时,它开始下载文件后几乎需要半秒钟发送请求,但是当我尝试了8.5mb时,几乎需要更多的东西。请求。
因此,是否有任何可以在下载管理器上设置的“超时”之类的东西,因为我认为可能是这种情况,即URL花费大量时间发送请求,并且在主要时间下,下载Manger的时间不超时。 (只是一个假设)
By large file i mean 8.5 MB and by small files I mean 80KB to 1MB.
while download manager can download files up to 2GB
The below code is able to download small files but not large one. For the large files it shows the downloading notification but then after some time shows 0kb/unknown (waiting for retry) in the notification. And in the logcat there is no error or any kind of message which can point to this problem. I'm calling this code from a normal service() class.
if (PermissionsUtil.hasExternalStoragePermission(context)) {
if (fileName.isNotBlank() && mimeType.isNotBlank()) {
// get download service and enqueue file
Toaster.showMessageShort(R.string.download_started)
manager?.let {
enq = it.enqueue(getDownloadManagerRequest(link, mimeType, fileName, withHeader))
context.registerReceiver(downloadCompletionReceiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
}
}
}
PS:
Im able to download large file in the postman using the same URL which is being provided to the download manger.
My network is working fine, I have tried with 6 different phone on different networks, all the showing the same behaviors.
On trying to listen to all the events while the (large) file is getting downloaded I get the below event
PAUSED_WAITING_TO_RETRY
Update
So I tried these test pdf files of various different sizes (100MB to 1GB), they are getting downloaded without any issue. But the 8.5MB whose URL im getting in an API response is showing the PAUSED_WAITING_TO_RETRY message.
And I also noticed one thing, when I tested the 1GB file in postman it just took almost half a second to send request after that it started downloading the file, but when I tried the 8.5MB one it almost takes more then a mintune in sending the request.
So is there anything like "Time Out" which can be set on a download manager because I think that might be the case, that the url is taking lot of time in sending the request and in the main time download manger runs out of time. (Just an assumption)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下载管理器只有可用的磁盘空间才有限制。要检查下载状态,您需要使用
inqueue(...)
方法返回的下载ID。检查此示例Download manager has limitation only with available disk space. To check downloading status you need to use download id returned by
enqueue(...)
method. Check this example