下载失败后,Android的DownloadManager无法恢复下载

时间:2019-02-18 05:36:07

标签: java android android-download-manager

要复制此问题,

  1. 我开始正常下载。
  2. 下载量达到40-50%左右时,我会断开WiFi。
  3. 在记录器中,我可以看到恢复下载,但是几秒钟后它却说失败了。

以下是日志:

02-18 10:34:04.366 20142 20783 D progressxxx: 40
02-18 10:34:04.366 20142 20783 D xxx1111 : Download in progress!
02-18 10:34:04.368  2579 20883 W DownloadManager: [211] Stop requested 
with status CANNOT_RESUME: Expected partial, but received OK
02-18 10:34:04.368  2579 20883 D DownloadManager: [211] Finished with 
status CANNOT_RESUME
02-18 10:34:04.369 20142 20783 D progressxxx: 40
02-18 10:34:04.369 20142 20783 D xxx1111 : Download in progress!
02-18 10:34:04.373 20142 20783 D progressxxx: 40
02-18 10:34:04.373 20142 20783 D xxx1111 : Download in progress!
02-18 10:34:04.376  2579 20883 V DownloadManager: MIME Type = 
application/vnd.android.package-archive
02-18 10:34:04.380 20142 20783 D progressxxx: 40
02-18 10:34:04.380 20142 20783 D xxx1111 : Download failed!
02-18 10:34:04.381  4875  5061 D JobServiceContext: 
sendStopMessageLocked stop reason: cancel() called by app, 
callingUid=10052 uid=10052 jobId=211
02-18 10:34:04.382  2579 20883 D DownloadManager: Send intent: mId:211 
status:489 mTitle:Download
02-18 10:34:04.385  2579 20883 I DownloadManager: Download 211 
finished with status CANNOT_RESUME
--------- beginning of crash
02-18 10:34:04.386 20142 20783 E AndroidRuntime: FATAL EXCEPTION: 
Thread-11
02-18 10:34:04.386 20142 20783 E AndroidRuntime: Process: 
com.example.sensen.gemineyedownloadmanager, PID: 20142
02-18 10:34:04.386 20142 20783 E AndroidRuntime: 
java.lang.ArithmeticException: divide by zero
02-18 10:34:04.386 20142 20783 E AndroidRuntime:    at 

1 个答案:

答案 0 :(得分:0)

由于我使用过Android Download Manager,因此很难保持暂停或继续并重新开始下载。如果要使用Android下载管理器使用此功能,则必须编写更多代码。您将必须维护文件路径等。

如果要使用其他下载库轻松实现它,则其中一个库为fetch,可以轻松实现和维护这些功能。