我有一个应用程序需要能够将 ~3GB 文件下载到用户指定的位置,我目前有以下代码,这似乎可以工作。即下载发生在下载管理器等中。
但是,一旦下载完成,它就无法出现在正确的位置,并且空间根本没有被占用。
这是我当前的代码:
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);
}
所以我的问题真的是为什么上面的效果不好?还是只是下载管理器难以下载如此大的文件?如果是这种情况,是否有更好的方法可以用来可靠地下载如此大的文件
下载完成后,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)