不完整下载的文件处理不完整、文件

2023-09-06 16:01:18 作者:拥你心安

我有在新的文件可以在用户的​​请求被添加ePub档案的收集。

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

现在,如果用户想下载一个新的ePub文件,因此点击,说获取最新书籍,和书籍开始下载到设备的SD卡。

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后退按钮他从互联网上断开他终止应用程序

然后下载文件保持完整。

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.

对此有何想法?

推荐答案

您需要检查文件是否试图打开它之前完全下载。

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

您可以存储下载的完整/共享preference不全,下载完成后,应进行更新的状态。试图加载文件之前检查该preference。

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.