下载的文件被自动删除 [英] Downloaded files get deleted automatically

查看:56
本文介绍了下载的文件被自动删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,用户可以下载一些文件.这些文件通过安卓下载管理器下载.但是,几周以来,数百名用户一直抱怨他们的文件每 8 到 12 天就会自动删除一次,甚至没有卸载应用程序.(可能还有更多的用户不愿意抱怨同样的事情.)

In my app, there are a few files that users can download. The files get downloaded via the android download manager. But, since a few weeks now, hundreds of users have been complaining that their files automatically keep deleting every 8-12 days, without them even uninstalling the app. (There might be many more users who haven't bothered to complain about the same.)

现在,可能有许多特定于用户的原因会在少数设备上发生这种情况.但是考虑到庞大的用户数量,我似乎做错了什么.

Now, there could be a number of user-specific reasons why that would happen on a few devices. But considering the huge number of users, it seems that I might have been doing something wrong.

为什么系统/下载管理器会自动删除文件?有没有办法通知系统或下载管理器不要删除某些文件?或者我应该在下载后重命名文件,以便将它们与下载管理器取消链接,并希望问题由此得到解决?

Why would the system/download manager delete the files automatically? Is there a way to inform the system or the download manager to not delete certain files? Or should I just settle with renaming the files after downloading, so as to unlink them from the download manager, and hope that the problem gets solved with just that?

这是我用来下载文件的代码:

Here's the code that I use to download the files:

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(trackLink));
request.setTitle(trackTitle);
request.setDestinationInExternalPublicDir("Tracks", trackTitle + ".mp3");
request.setVisibleInDownloadsUi(false);
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);

推荐答案

我也遇到了这个问题.查看 DownloadIdleService 的源代码,如果下载设置为在 UI 中不可见,它们会在 7 天后被删除,因为它们被认为是陈旧的".这是DownloadIdleService 中的javadoc:

I also came across this issue. Looking at the source for DownloadIdleService it appears that if the download are set to not be visible in the UI they're deleted after 7 days as they're considered "stale". Here's the javadoc fromDownloadIdleService:

/**
 * Remove stale downloads that third-party apps probably forgot about. We
 * only consider non-visible downloads that haven't been touched in over a
 * week.
 */

https://android.googlesource.com/platform/packages/providers/DownloadProvider/+/master/src/com/android/providers/downloads/DownloadIdleService.java#110

这篇关于下载的文件被自动删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆