如何为下载文件命名

时间:2016-08-05 14:53:32

标签: android

我正在使用Android DownloadManager 从服务器下载视频。我想给自己的每个视频命名。默认情况下,视频名称为downloadfile-6.bin。

String servicestring = Context.DOWNLOAD_SERVICE;
DownloadManager downloadmanager;
downloadmanager = (DownloadManager) getSystemService(servicestring);
Uri uri = Uri.parse(links.get(0));
DownloadManager.Request request = new DownloadManager.Request(uri);
Long reference = downloadmanager.enqueue(request);

建议将不胜感激。

1 个答案:

答案 0 :(得分:3)

您可以使用DownloadManager.RequestsetDestinationInExternalFilesDir(...)通过setDestinationInExternalPublicDir(...)对象进行设置。见最后一行:

request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
       .setAllowedOverRoaming(false)
       .setTitle("DownloadTitle")
       .setDescription("DownloadDesc")
       .setDestinationInExternalPublicDir("/mypath", "filename.jpg");

<强>来源: