0

I have an application that needs to be able to download a ~3GB file to a user specified location, I currently have the below code, which seems to work. i.e the download takes place with it showing up in the download manager etc.

However once the download is complete it fails to appear in the correct location, and the space has not been taken up at all.

This is my current code:

 public void file_download(String uRl) {
install_txt = AppPreferences.getPrefs().getString(
                "path",
                Environment.getExternalStorageDirectory().getPath()
                + "/test.img");

            DownloadManager mgr = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE);

            Uri downloadUri = Uri.parse(uRl);
            DownloadManager.Request request = new DownloadManager.Request(
                    downloadUri);

            request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
                    .setAllowedOverRoaming(false).setTitle("test")
                    .setDescription("Downloading test")
                    .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS , install_txt);

            mgr.enqueue(request);
        }

So my question really is why does the above not work well? or is it just that the download manager struggles to download such large files? If that is the case is there a better method I could use to download reliably such a large file

After the download finishes the below is shown in the logcat

07-19 13:19:28.112: W/DownloadManager(19199): Exception for id 8952: Invalid int: "3891000000"
07-19 13:19:28.112: W/DownloadManager(19199): java.lang.NumberFormatException: Invalid int: "3891000000"
07-19 13:19:28.112: W/DownloadManager(19199):   at java.lang.Integer.invalidInt(Integer.java:138)
07-19 13:19:28.112: W/DownloadManager(19199):   at java.lang.Integer.parse(Integer.java:378)
07-19 13:19:28.112: W/DownloadManager(19199):   at java.lang.Integer.parseInt(Integer.java:366)
07-19 13:19:28.112: W/DownloadManager(19199):   at java.lang.Integer.parseInt(Integer.java:332)
07-19 13:19:28.112: W/DownloadManager(19199):   at com.android.providers.downloads.DownloadThread.handleEndOfStream(DownloadThread.java:516)
07-19 13:19:28.112: W/DownloadManager(19199):   at com.android.providers.downloads.DownloadThread.transferData(DownloadThread.java:314)
07-19 13:19:28.112: W/DownloadManager(19199):   at com.android.providers.downloads.DownloadThread.executeDownload(DownloadThread.java:278)
07-19 13:19:28.112: W/DownloadManager(19199):   at com.android.providers.downloads.DownloadThread.runInternal(DownloadThread.java:193)
07-19 13:19:28.112: W/DownloadManager(19199):   at com.android.providers.downloads.DownloadThread.run(DownloadThread.java:142)
DevWithZachary
  • 3,545
  • 11
  • 49
  • 101
  • Do smaller files work OK? Are you reasonably sure it's just a problem with large files? – Ken Wolf Jul 18 '13 at 10:24
  • @KenWolf yes smaller files seem to work ok – DevWithZachary Jul 18 '13 at 10:27
  • Thanks - Are you sure there's enough space on the device? – Ken Wolf Jul 18 '13 at 10:29
  • @KenWolf yes I check for free space before running the above function, and on my test device I have 10GB free to be sure – DevWithZachary Jul 18 '13 at 10:31
  • Your `setDestinationInExternalPublicDir()` call is odd. Your code implies that the default value of `install_txt` will be something like `/mnt/sdcard/test.img`, which is a rather strange set of subdirectories to put in the user's `Downloads` directory. Beyond that, have you tried putting a 3GB file in your desired location by any other means, such as DDMS or **`adb push`**? – CommonsWare Jul 18 '13 at 11:02
  • @CommonsWare yes the above code was copied wrong, I was trying to get it to download to /mnt/sdcard/test.img but couldn’t get this work either so was downloading it to the environments Download folder to test. yes I can move the file on to the device via other means – DevWithZachary Jul 18 '13 at 11:08
  • Any interesting messages in LogCat around the time the download is flagged as complete? – CommonsWare Jul 18 '13 at 11:09
  • @CommonsWare shall have to try the download again, but I did not see anything last time – DevWithZachary Jul 18 '13 at 11:12
  • @CommonsWare seems there was some issue with it see changes to question – DevWithZachary Jul 19 '13 at 12:22
  • you can always use a library like this one here: https://blog.mindorks.com/how-to-download-a-file-in-android-and-show-the-progress-very-easily – Miguel Tomás Nov 11 '20 at 18:06

1 Answers1

1

That error message would suggest that DownloadManager, at present, is limited to files that are 2147483647 (Integer.MAX_VALUE) bytes or smaller.

There has been a bug report filed for this already, with no response from Google at present.

In the meantime, I'd see if you could arrange to split that ~3GB file into two smaller files. If not, you may need to do the downloading yourself.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491