我使用Android下载管理器从服务器下载文件,因为它处理网络错误并继续下载。
它工作正常,我可以使用它来下载文件,
问题:当我开始下载时,它已成功完成,文件也会下载一次,但它将下载的文件存储/显示在两个目录中,一个是默认下载目录的android第二个是自定义目录,由我创建,因为我只想在我的自定义目录中存储/显示,然后只想从该目录文件中读取。
问题:我如何只在自定义创建的目录中存储/显示下载的文件?
以下是我用下载管理器下载文件的代码。
public void downloadWithManager(String urlPath) {
Long tsLong = System.currentTimeMillis() / 1000;
File direct = new File(Environment.getExternalStorageDirectory() + "/Demo");
if (!direct.exists()) {
direct.mkdirs();
}
downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Uri Download_Uri = Uri.parse(urlPath);
DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
//Restrict the types of networks over which this download may proceed.
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
//Set whether this download may proceed over a roaming connection.
request.setAllowedOverRoaming(false);
//Set the title of this download, to be displayed in notifications (if enabled).
request.setTitle(tsLong.toString() + ".mp4");
//Set a description of this download, to be displayed in notifications (if enabled)
request.setDescription("Download in progress...");
//Set the custom local destination for the downloaded file
request.setDestinationInExternalPublicDir("/Demo", tsLong.toString() + ".mp4");
//Enqueue a new download and same the referenceId
downloadReference = downloadManager.enqueue(request);
}
谢谢。