URLConnection getContentLength() on Android 4.1.1 returns -1
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/10439829/urlconnection-getcontentlength-returns-1">URLConnection.getContentLength() returns -1</a>  </p>
</blockquote>



<p>I want to download a file which is on a server. I want to get the size by using getContentLenth function. It works well with Android 2 but the function returns -1 with Android 4.1.1. I really need this size in order to show a download progress bar.</p>

<p>Here is my code :</p>

<pre><code>URL url = new URL(apkPathName);
URLConnection connection = url.openConnection();
connection.connect();
int lenghtOfFile = connection.getContentLength();
</code></pre>

<p>Thanks for your help</p>
