我正在使用
代码:
DownloadManager
下载我的应用程序文件。如果我将URL再次放入DownloadManager
中,它会下载该文件并在末尾加上-1 filename-1.file
。是否有一种方法可以让DownloadManager
不必再次下载它?还是我必须自行检查?代码:
private void downloadImages(final List<SomeClass> data) {
RuntimeExceptionDao<SomeClass, Integer> someDao = DatabaseAdapter.getInstance().getSomeDao();
DownloadManager downloadmanager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
for(SomeClass someClass : data){
DownloadManager.Request request = getRequest(someClass);
someClass.mDownloadId = downloadmanager.enqueue(request);
someDao.createOrUpdate(someClass);
}
}
private DownloadManager.Request getRequest(SomeClass someClass) {
Uri uri = Uri.parse(someClass.mImage);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
request.setVisibleInDownloadsUi(false);
request.setDestinationInExternalFilesDir(mContext, Environment.DIRECTORY_DOWNLOADS, car.getFileName());
return request;
}