I have to download a file and I'm using this code, which is basically an AsyncTask
that is meant to update a progress bar. But, since I don't know what's the file size I've been having to use the spinner progress bar. So, how can I get the file size before start downloading it so that I can use a normal progress bar?
views:
186answers:
1
+3
A:
you can get a header called Content-Length
form the HTTP Response object that you get, this will give you the length of the file.
you should note though, that some servers don't return that information, and the only way to know the actual size is to read everything from the response.
Example:
URL url = new URL("http://server.com/file.mp3");
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
int file_size = urlConnection.getContentLength();
Reflog
2010-06-06 07:12:52