我在使用DownloadManager类从我的服务器下载视频时注意到一些奇怪的行为。
视频下载得很好,但当我尝试使用public int remove (long... ids)
功能删除它们时,物理文件不会被删除,内存最终也不会被释放。
以下是我将DownloadManager.Request对象提供给DownloadManager的enqueue
函数的方法:
Uri target = Uri.fromFile(new File(destinationFolder, Sha1Util.SHA1(url)));
Request request = new Request(Uri.parse(url));
request.setDestinationUri(target);
request.setNotificationVisibility(Request.VISIBILITY_HIDDEN);
request.setVisibleInDownloadsUi(false);
其中destinationFolder
= /storage/emulated/0/Android/data/{app's_package_name}/{user_name}
注意:删除功能在Lollipop设备上运行正常,但不适用于以前的版本。