检查android下载中是否存在该图像

检查android下载中是否存在该图像,android,download,android-download-manager,Android,Download,Android Download Manager,我想检查图像是否已经存在于Android的下载文件夹中。在那里,如果部分不工作。如果文件已经存在(例如:图像名称-hair_61),则在第二次下载同一图像时,它将作为hair_61-1下载该文件。我已经尝试了下面的代码。我想显示一条消息,如果文件已经存在,并限制进一步下载,我该怎么办 Appconstants.java: public class AppConstants { //storage public static final String MEDIA_FOLDER = Environ

我想检查图像是否已经存在于Android的下载文件夹中。在那里,如果部分不工作。如果文件已经存在(例如:图像名称-hair_61),则在第二次下载同一图像时,它将作为hair_61-1下载该文件。我已经尝试了下面的代码。我想显示一条消息,如果文件已经存在,并限制进一步下载,我该怎么办

Appconstants.java:

public class AppConstants {

//storage
public static final String MEDIA_FOLDER = Environment.getExternalStorageDirectory()+ File.separator + "PubImg";
public static final String DOWNLOADS_FOLDER = MEDIA_FOLDER + File.separator + "Downloads/";
}
下载功能:

downloadimage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DownloadManager.Request request = new DownloadManager.Request(
                    Uri.parse(imgUrl));
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.
                    Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

            FileUtils.createDirectory(AppConstants.DOWNLOADS_FOLDER);
            File imageFile = new File(AppConstants.DOWNLOADS_FOLDER + "hair_" + photoID + ".jpg");
            if(imageFile.exists()) {
                Toast.makeText(getApplicationContext(), "Image is Already downloaded",
                        Toast.LENGTH_LONG).show();
            }
            else {
                request.setDestinationUri(Uri.fromFile(imageFile));

                DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                dm.enqueue(request);

                Toast.makeText(getApplicationContext(), "Downloading File",
                        Toast.LENGTH_LONG).show();
            }
        }
        });

文件=新文件(…文件路径…);如果(file.exists())Toast(…file exists…);如果你唯一想问的是如何检查文件是否存在,请不要发布下载管理器的代码。检查文件是否不存在后,可以启动下载管理器。在那之前不要提出请求。但这是另一个故事。我如何才能阻止该图像再次被下载?如果文件已经存在,请不要启动下载管理器。file file=新文件(…文件路径;如果(file.exists())Toast(…file exists…)不起作用