0
08-03 11:07:48.814: I/System.out(25283): DOWNLOAD LOCATION: /Podcasts/NikolaiBegg_2013X.mp4   
08-03 11:13:27.657: I/System.out(25283): CHECKED LOCATION: /Podcasts/NikolaiBegg_2013X.mp4
08-03 11:14:46.830: I/System.out(27324): Does Not Exist Locally  

This is an unusual situation that I find myself in. I am downloading some video file from the internet in my app, the name of which is extracted from the URL. Somehow, it always tells me that the file does not exist despite me having downloaded the file.

I am downloading the file as follows, using DownloadManager.Request:

        // This put the download in the same Download dir the browser uses 
        r.setDestinationInExternalPublicDir(Environment.DIRECTORY_PODCASTS, fileName);

        // TODO delete later
        System.out.println("DOWNLOAD LOCATION: " + 
                new File(Environment.DIRECTORY_PODCASTS,fileName).getAbsolutePath());   

and I check the existence of the file as existsLocally():

        File f = new File(Environment.DIRECTORY_PODCASTS, fileName);
        System.out.println("CHECKED LOCATION: " + f.getAbsolutePath());
        return f.exists();  

Then why does it return false all the time?

Here is my checking logic:

if(existsLocally(getFileNameFromEnclosure(enclosure))){
        System.out.println("Exists Locally");
}else{
        System.out.println("Does Not Exist Locally");
}
An SO User
  • 24,612
  • 35
  • 133
  • 221

1 Answers1

1

I think it's because you are not requesting the external storage when you check for the file. Referring to the documentation for Environment, try this:

File path = Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_PODCASTS);
File f = new File(path, fileName);
Sparky
  • 8,437
  • 1
  • 29
  • 41