【问题标题】:Android downloadmanager download location安卓下载管理器下载位置
【发布时间】:2017-10-05 21:48:35
【问题描述】:

我正在尝试使用 DownloadManager 将文件从 url 下载到 /storage/emulated/0/Download

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,如果卸载了应用程序,文件就会从设备中删除。

【问题讨论】:

    标签: java android download uri android-download-manager


    【解决方案1】:

    你试过了吗

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-23
      • 2012-10-31
      • 1970-01-01
      • 2010-12-19
      • 2012-02-29
      • 2016-05-25
      相关资源
      最近更新 更多