I'm using the following code for downloading file in my Android project:
URL url = new URL(fileUrl);
URLConnection conection= url.openConnection();
conection.setDoOutput(true);
conection.connect();
int lenghtOfFile = conection.getContentLength();
If fileUrl is apk, lenghtOfFile always return -1.
But if it is image, video type,... lenghtOfFile return is exactly.
Why ?
I'm using eclipse, Android SDK revision 23.
The content length is not always available because by default Android request a GZIP compressed response. Source: Android documentation.
Quoting the link:
Whether or not the response then actually is compressed depends on the server of course.