一些标头参数应该有助于检测正确的内容长度。
答案 0 :(得分:0)
/* Get download file size returned from http server header. */
public static long getDownloadUrlFileSize(String downloadUrl) {
long ret = 0;
HttpURLConnection con = null;
try {
if (downloadUrl != null && !TextUtils.isEmpty(downloadUrl)) {
URL url = new URL(downloadUrl);
con = (HttpURLConnection) url.openConnection();
con.setRequestProperty("Accept-Encoding", "identity;q=1, *;q=0");
System.out.println("Length : " + con.getContentLength());
ret = con.getContentLength();
}
} catch (Exception ex) {
Log.e(TAG_DOWNLOAD_MANAGER, ex.getMessage(), ex);
} finally {
if (con != null)
con.disconnect();
return ret;
}
}