首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用下载管理器下载文件

使用下载管理器下载文件
EN

Stack Overflow用户
提问于 2015-10-09 00:06:49
回答 1查看 10.1K关注 0票数 7

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

下面是我正在做的事情

代码语言:javascript
复制
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);
}

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

代码语言:javascript
复制
 BroadcastReceiver onNotificationClick = new BroadcastReceiver() {
    public void onReceive(Context ctxt, Intent intent) {

    }
};

请帮帮忙

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-09 00:44:58

最后只用了2行代码就解决了这个问题

代码语言:javascript
复制
 request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33020815

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档