0
내 안드로이드 응용 프로그램을 실행할 때 다운로드 시간이 필요합니다. 그래서 2 Log와 System.currentTimeMillis()
을 추가했습니다. 그러나, 나는이 공구를 둘 정확한 위치를 찾아 낼 수 없다.다운로드 시간을 얻는 방법
시작 시간을 얻으려면, 나는이 추가 :
System.out.println("Fin téléchargement : "+System.currentTimeMillis());
period=(System.currentTimeMillis()-period);
System.out.println("La durée de téléchargement : "+period+"ms");
그리고이 파일을 다운로드하는 모든 코드 :
period=System.currentTimeMillis();
System.out.println("Début téléchargement : "+System.currentTimeMillis());
종료 시간을 SER하기 위해, 나는이 추가
을class DownloadFileAsync extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(DIALOG_DOWNLOAD_PROGRESS);
}
@Override
protected String doInBackground(String... aurl) {
int count;
try {
File vSDCard = null;
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
vSDCard = Environment.getExternalStorageDirectory();
File vFile = new File(vSDCard.getParent() + "/" + vSDCard.getName() + "/"
+ "image.jpg");
URL url = new URL(aurl[0]);
URLConnection conexion = url.openConnection();
int lenghtOfFile = conexion.getContentLength();
Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);
conexion.connect();
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(vFile);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress("" + (int) ((total * 100)/lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
}
} catch (Exception e) {
Log.d("ImageManager", "Error: " + e);
}
return null;
}
protected void onProgressUpdate(String... progress) {
Log.d("ANDRO_ASYNC", progress[0]);
ProgressDialog.setProgress(Integer.parseInt(progress[0]));
}
@Override
protected void onPostExecute(String unused) {
dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
}
}
제발 당신의 제안이 필요합니다.
감사합니다. 나는 'conexion.connect();의 직전과 직전에 첫 번째와 두 번째 블록을 설정했습니다. 결과를 IDM과 비교했습니다. 그것은 같은 결과를 낳았다. – Linconnue55
정확도를 높이려면 나노 시간을 사용할 수 있습니다. –