Possible duplicate
I am downloading large zip files using Android DownloadManager. I have listview that shows list of all zip files and user can tap item to start downloading. Only one item can be downloaded at a time. When new list item starts downloading while other download is in progress i remove previous download id from queue. Everything is working fine. But sometimes i am getting ERROR_FILE_ERROR on LG g2 device OS 5.0.2. Here is code:
Uri uri = Uri.parse(path);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setAllowedOverRoaming(false);
request.setVisibleInDownloadsUi(false);
String localStorageBasePath = FileUtils.zipDirectory(context).getAbsolutePath() + File.separator + fileName;
Uri localStorageBasePathUri = Uri.fromFile(new File(localStorageBasePath));
request.setDestinationUri(localStorageBasePathUri);
Long downloadId = downloadManager.enqueue(request);
It is working fine on other devices including nexus 5, samsung s3, note2, huawei etc. When i start downloading a file it instantly stops/failed with reason DownloadManager.ERROR_FILE_ERROR. I have tried to remove/clean external storage directory, making sure that its not ERROR_INSUFFICIENT_SPACE error etc. but it didn't work. Any help?
You can find downloads on Android in My Files or File Manager. You can find these apps in the app drawer of your Android device. Within My Files or File Manager, navigate to the Downloads folder to find everything you downloaded.
This might be a bit more bullet-proof:
public void file_download(String path, String filename)
{
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).mkdirs();
Uri uri = Uri.parse(path);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setDescription("");
request.setTitle("");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
{
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setAllowedOverRoaming(false);
request.setVisibleInDownloadsUi(false);
request.setDestinationInExternalFilesDir(context, DIRECTORY_DOWNLOADS, fileName);
//String localStorageBasePath = FileUtils.zipDirectory(context).getAbsolutePath() + File.separator + fileName;
//Uri localStorageBasePathUri = Uri.fromFile(new File(localStorageBasePath));
//request.setDestinationUri(localStorageBasePathUri);
DownloadManager downloadManager = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE);
Long downloadId = downloadManager.enqueue(request);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With