Search code examples
javaandroidandroid-download-manager

How to avoid corrupted downloads via Android DownloadManager?


Here's the code i'm using:

DownloadManager.Request request = new DownloadManager.Request(uri);
request.setTitle("Download: " + name);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setDestinationInExternalPublicDir(DIRECTORY_DOWNLOADS, name);
request.setMimeType("application/octet-stream");
return dl_manager.enqueue(request);

I run this code in an android emulator via Android Studio, have it download a file over 50mb, then use the AS Device File Explorer to download the file and compare it to what i have local. Result: Various bytes are different in the downloaded version.

Why would this happen?


Solution

  • As of now, it appears that the emulator is at fault. Running the app on a physical phone hasn't resulted in any corrupted downloads at all.