[英]Android downloadmanager download location
我正在嘗試使用DownloadManager將文件從url下載到/storage/emulated/0/Download
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);
我已確認path
確實返回所需的下載路徑。 我的問題是,當文件實際下載時,它們最終/documents/blah
,如果卸載了應用程序,則會從設備中刪除文件。
你有沒有嘗試過
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, file.name());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.