My application depends heavily on android DownloadManager
component to download files with approximate size of 3-10 mega bytes.
when scaling up (to millions of downloads) the big picture is clear:
~50% of all downloads are failing due to ERROR_HTTP_DATA_ERROR.
I'm getting this info from google analytics
according to the documentation, this error code stands for:
Value of COLUMN_REASON when an error receiving or processing data occurred at the HTTP level.
I found this documentation not very informative.
there are plenty of http errors out there.
and what about network disconnection in the middle of the download? does it also triggers the ERROR_HTTP_DATA_ERROR
error after failing all the download's manager retry attempts?
It would be great if someone could help me to understand:
- is there any way to get from
DownloadManager
more information about the exact http error? - what are the most common situations
ERROR_HTTP_DATA_ERROR
can be fired by download manager?
another point that worth mentioning: while this errors accruing - the user is connected to WIFI network (I'm setting download manager to download only over wifi)
please don't suggest me not to use download manager at all. I know about this option, advantages and disadvantages. I'm saving this option as a last resort.
Looking at the Source of DownloadManager
ERROR_HTTP_DATA_ERROR
is returned by a methodgetErrorCode(int)
this is the exact line:android.provider.Downloads
has statuses which are masked here withDownloadManager
class's own constants, in its source:Now you got to find out what causes HTTP error
495
. After Googling a bit I came to find out that this error response code is Google related only and is often produced when downloading apps from the playstore.A fix suggested to
Go to Settings - Apps- All- Download manager and Clear data.
So in conclusion of my limited research, I think its an underlying
DownloadManager
implementation related problem rather then some network or server problem, and since no definite solution/workaround is available (my friends also faced a similar situation) you should try other alternatives.Without seeing any code it's guess work. From the docs:
This will give you a standard http error from which you can find a 6.1.1 Status Code and Reason Phrase. If you are having millions of downloads, and these are from a limited array of sites, this could be a problem that is beyond your app, as the website's servers may not be coping with the traffic.
Internet connectivity issues could cause;
Possibly. For it to throw this type of error, it needs to be a problem with the app communicating with and/or attempting to and/or finishing the download at the website.
Beyond using try and catches and logging the errors in the relevant methods where your app uses the
DownloadManager
, and then testing and waiting for the logcat when you get this error, the other option would be to remote use a library or third party tool to get remote error logging and crash reports of your deployed app.There are many third party services and libraries that offer this, I am using one of the reputable open source libraries as an example.
As for online error and crash logging, ACRA is open source and provides this feature. This used to use Google products to store reports freely, but as usage has increased, Google has withdrawn this support, however there are features offered by ACRA and other providers, or you can manage your own reporting, but this may incur cost.
Implementing this is within the app code is relatively straight forward, by creating a class that hooks into your app by extending the application class and launches with the application.
You'll also need to set up the back end reporting, and there are details provided on how to do this, as the options become increased. More detail can be found here, BasicSetup.
This blog by The Cheese Factory gives a detailed view of set up and other options for online error reporting How to setup ACRA, an Android Application Crash Tracking system, on your own host Application Crash Reports on Android
This will mean an update to your app, but you're going to have to do this anyway from the sounds of it.
It's difficult to say exactly what is the reason for the error you are getting. The error code you are receiving is too general.
Things I would do in order to resolve the issue:
Try to see if there is any correlation between server load or server activity and the number of download failures. This would help determine if the problem originates in the server. If it does - you may increase your resources on the server side or try to find a way to decrease the load on your servers to minimize the download related problems. Heavy server loads or a large number of concurrent downloads may cause problems like the one you are having (bottle-necks, timeouts, locked resources on the server side etc.).
If you come to the conclusion that your problem in on the client side - I would consider replacing the Android Download Manager with another one or write your won code to download the file (s).
I'd have to say that Ms Yvette's offer to add more logging is important. I do it in all my apps. Once you post more information about the problem - we'll be able to pin-point the problem and resolve it more quickly.