我调用以下函数来获取要下载的文件总大小:
private Uri askForFileSizeFromURL(URL url, String fileName) {
try {
URLConnection conn = url.openConnection();
HttpURLConnection httpConnection = conn instanceof HttpURLConnection ? (HttpURLConnection ) conn : null;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK){
bytesToDownload += httpConnection.getContentLength();
return null;
}
}
catch(ConnectException e) {
Log.d("2ndGuide", "ConnectException." + e);
downloadAborted = true;
return null;
}
catch(IOException e)
{
Log.d("2ndGuide", "IO Exception." + e);
}
return null;
}
我调用此功能31次,需要超过23次。没有这个调用,循环需要320ms。所以问题来自这段代码。
是否有更快的方法从Internet上的远程服务器获取文件大小?
此致 阿兰