public void onClick(DialogInterface dialog, int id) {
Uri u = Uri.parse(url);
File f = new File("" + u);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setTitle("");
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, f.getName());
// just my bullshit here please correct here
if (f.exists()) {
File sdcard = Environment.getExternalStorageDirectory();
File from = new File(sdcard,f.getName());
File to = new File(sdcard,"*"+f.getName());
from.renameTo(to);
}
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
}
我有这个小代码,然后当单击它从 url 下载文件但是当文件已经下载并且具有相同的名称时它只是显示失败,我如何检查文件是否已经存在并让 DownloadManager 以不同的名称下载该文件?