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)
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top