android - 如何给下载的文件起名字

标签 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);

建议将不胜感激。

最佳答案

您可以使用 setDestinationInExternalFilesDir(...)setDestinationInExternalPublicDir(...) 通过 DownloadManager.Request 对象设置它。看最后一行:

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

来源:

关于android - 如何给下载的文件起名字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38792200/

相关文章:

java - 如何在 android 中创建可重用的 AsyncTasks?

java - Android hashmap按钮id

android - ionic 构建到/dist 文件夹而不是/www

android - 如何从耳机插孔获取电力?

java - ListAsGridBaseAdapter 仅在项目数为偶数时显示网格项目

android - Firebase - 通过 ID 列表获取元素

android - onActivityResult 不在 Fragment 中调用

android - 从 Android NFC Intent 获取 URI

android - 运行 AOSP make 测试

java - Android 中的静态字段