我有一个关于下载管理器的问题。我要从一个站点下载一个文件。当我设置默认下载目录(Environment.DIRECTORY_DOWNLOAD)时,一切正常,我的下载开始了。但是,如果我尝试更改目录,我的应用程序不会下载该文件。特别是,我希望我的文件进入下载中的文件夹,例如 /storage/sdcard/Download/myFolder。我该如何解决?
File mydownload = new File (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+ "/myFolder");
if (!mydownload.exists()){
mydownload.mkdir();
}
String url = sUrl[0];
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(mydownload.getAbsolutePath(),"Myfile.extension");
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);