使用下载管理器下载文件

编程入门 行业动态 更新时间:2024-10-22 22:57:43
本文介绍了使用下载管理器下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用DownloadManager类从服务器下载文件

I am downloading files from server using DownloadManager class

这是我在做什么

public void downloadPdf(String url, String sem, String title, String branch) { Uri Download_Uri = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(Download_Uri); //Restrict the types of networks over which this download may proceed. request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE); //Set whether this download may proceed over a roaming connection. request.setAllowedOverRoaming(false); //Set the title of this download, to be displayed in notifications (if enabled). request.setTitle("Downloading"); //Set a description of this download, to be displayed in notifications (if enabled) request.setDescription("Downloading File"); //Set the local destination for the downloaded file to a path within the application's external files directory request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, title + "_" + branch + "_" + sem + "Year" + System.currentTimeMillis() + ".pdf"); //Enqueue a new download and same the referenceId downloadReference = downloadManager.enqueue(request); }

下载完成后,如果用户单击通知,它将打开该文件,我应该在这段代码中做什么

thing is when download is complete if then user clicks on notification it should open that file what should i do in this code

BroadcastReceiver onNotificationClick = new BroadcastReceiver() { public void onReceive(Context ctxt, Intent intent) { } };

请帮助

推荐答案

最后只用2行就解决了

request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

更多推荐

使用下载管理器下载文件

本文发布于:2023-11-28 13:14:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642559.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管理器   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!