1
我必須在我的android應用程序中獲得下載時間,這就是爲什麼我需要確定下載的開始和結束時間以確定期間下載的時間。 我加在一開始,這些線路和doInBackground
結束:獲取開始和結束下載的時間
Log.v("Download_INFO","i begin downloading at : "+" "+dt.getHours()+"h "+dt.getMinutes()+"min "
+dt.getSeconds()+"sec");
Log.v("Download_INFO","i complete downloading at : "+" "+dt.getHours()+"h "+dt.getMinutes()
+"min "+dt.getSeconds()+"sec");
但出人意料的是,我有一段時間了。我無法理解的原因
這是我doInBackground
方法:
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() + "/"
+ "downloadTest.jpg");
URL url = new URL(aurl[0]);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);
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);
}
Log.v("Download_INFO","i complete downloading at : "+" "+dt.getHours()+"h "+dt.getMinutes()
+"min "+dt.getSeconds()+"sec");
output.flush();
output.close();
input.close();
System.out.println(currentDateTimeString);
}
} catch (Exception e) {
Log.d("ImageManager", "Error: " + e);
}
return null;
}
有什麼問題,請!
偉大的想法。這只是「System.currentTimeMillis」 – Linconnue55