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
我发现这是一个不寻常的情况。我正在我的应用程序中从互联网上下载一些视频文件,其名称是从URL中提取的。不知何故,它总是告诉我,尽管我已下载文件,但该文件仍然不存在。
我使用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());
我检查文件的存在为 existsLocally():
File f = new File(Environment.DIRECTORY_PODCASTS, fileName);
System.out.println("CHECKED LOCATION: " + f.getAbsolutePath());
return f.exists();
那为什么它一直都会返回false?
这是我的检查逻辑:
if(existsLocally(getFileNameFromEnclosure(enclosure))){
System.out.println("Exists Locally");
}else{
System.out.println("Does Not Exist Locally");
}
答案 0 :(得分:1)
我认为这是因为您在检查文件时没有请求外部存储。请参阅Environment的文档,试试这个:
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PODCASTS);
File f = new File(path, fileName);