gpt4 book ai didi

android - DownloadManager 设置标题更改我的文件名

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:31:07 28 4
gpt4 key购买 nike

我在我的应用程序中使用 DownloadManager 从 Internet 下载文件。这是我的代码。

DownloadManager downloadManager = (DownloadManager) ui.activity.getSystemService(Activity.DOWNLOAD_SERVICE);
Uri Download_Uri = Uri.parse("http://dl.appvn.com/appvn.apk");
DownloadManager.Request request = new DownloadManager.Request(Download_Uri);


request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
.
request.setAllowedOverRoaming(false);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"appvn.apk");

request.setTitle("AppStoreVN");

request.setDescription("Android Data download using DownloadManager.");

downloadManager.enqueue(request);

我使用 setTitle 和 setDescription 来更改通知栏上显示的信息。但它也改变了我的文件名,如标题(“AppStoreVN”,而它应该是“appvn.apk”)。有人有想法吗?谢谢

最佳答案

for getting name of downloading file i used:

String nameOfFile = URLUtil.guessFileName(mDownloadFileUrl, null,
MimeTypeMap.getFileExtensionFromUrl(mDownloadFileUrl));

then for setting title and description of DownloadManager

request.setDescription(nameOfFile);
request.setTitle(nameOfFile);

Then for setting actual file name of downloaded file in directory path

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
/*here the name of file is set*/nameOfFile);

希望这对你有帮助:)

关于android - DownloadManager 设置标题更改我的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26815529/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com