Search code examples
androidzipunzipdownload-manager

Download zip file using download manager


I want to download a zip file from a particular zip link and then unzip that zip file in android.What should i do? Can I use android download manager?


Solution

  • Yes you can use it, here is a small snippet:

    DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Request req = new DownloadManager.Request(Uri.parse("url-of-the-zip"));
    req.setDestinationExternalFilesDir(Environment.DIRECTORY_DOWNLOADS, "filename.zip");
    long id = dm.enqueue(req);
    

    The id can later be used to request the local Uri of the downloaded file using DownloadManager.getUriForDownloadedFile(int). To unzip this file you can use ZipFile