简体   繁体   中英

Android downloadmanager download location

I'm trying to download a file from a url to /storage/emulated/0/Download using the DownloadManager

DownloadManager downloadManager = (DownloadManager) context.getApplicationContext().getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.allowScanningByMediaScanner();
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setAllowedOverRoaming(false);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setTitle("blah");
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsoluteFile().toString();
System.out.println(path);
request.setDestinationInExternalPublicDir(path, title);
request.setVisibleInDownloadsUi(true);

final long downloadReference = downloadManager.enqueue(request);

And I've confirmed path does return the desired Downloads path. My problem is that when the files actually download they end up /documents/blah and if the app is uninstalled the files are removed from the device.

你有没有尝试过

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, file.name());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM