Reputation: 5850
I am using this code (inside an AsyncTask) to download files:
URL u = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection)u.openConnection();
conn.setRequestMethod("GET");
conn.setDoOutput(true);
conn.connect();
int lenghtOfFile = conn.getContentLength();
Log.d("MyApp", "length of file = " + lenghtOfFile);
...
On Android 2.3, it works well and returns the correct length. Since 4.0 however, it always returns -1. What has been changed between these 2 versions, and how can I fix it?
Upvotes: 1
Views: 1484
Reputation: 17
Commenting this statement, fixed my issue too :
conn.setDoOutput(true);
Upvotes: 0