Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download Files Using download manager

I am downloading files from server using DownloadManager class

Here is what i am doing

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) {

    }
};

Please help

like image 759
Android Avatar asked Oct 08 '15 16:10

Android


People also ask

What is free download manager?

Free Download Manager is a tool that helps you to adjust traffic usage, organize downloads. It is one of the best download manager for PC which helps you to control file torrents priorities, and download large files, and resume broken downloads.

How to download files from an URL using Download Manager?

In this article, we are going to learn how to download files from an URL using Download Manager. Here we will be simply adding the link of the file available online. When we click on the Button it will be downloaded automatically to our phone storage.

What is the Best Download Manager for Windows 10?

1) Free Download Manager Free Download Manager is a tool that helps you to adjust traffic usage, organize downloads. It is one of the best download manager for PC which helps you to control file torrents priorities, and download large files, and resume broken downloads.

What is the use of Download Manager in Android?

This download manager in Android allows you to download three files simultaneously. Smart algorithm for increased speed of downloading. This file download manager helps you to download files in the background and resume after failure. You can change the maximum speed in real time.


Video Answer


1 Answers

Finally fixed this by just 2 lines

 request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
like image 102
Android Avatar answered Sep 30 '22 14:09

Android