Dealing with incomplete downloaded file

2019-06-08 08:32发布

I have collection of ePub files in which new files can be added on user's request.

Now if user wants to download a new ePub file and hence clicks on, say get latest book, and book starts downloading to device sdcard.

Now before download gets completed, if user

  • presses back button
  • he is disconnected from internet
  • he terminates the application

then downloaded file remains incomplete.

When next time user opens the app, it tries to open that incomplete file resulting in possible crash of the app.

Any idea on this?

1条回答
beautiful°
2楼-- · 2019-06-08 09:23

You need to check if the file is fully downloaded before attempting to open it.

You could store the status of the download as complete/incomplete in shared preference, which should be updated when the download is complete. Check this preference before trying to load the file.

查看更多
登录 后发表回答