最初の時間とダウンロードの終わりを取得します
-
27-10-2019 - |
質問
Androidアプリケーションでダウンロードの時間を取得する必要があります。そのため、Dowloadの開始と終了の時間を決定して、期間ODのダウンロードを決定する必要があります。私はこれらの線を最初と終わりに追加しました 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;
}
何が問題なのですか!
解決
両方のログステートメントに同じ日付オブジェクトを使用しているようです。 「完了した」ログステートメントの前にこれを追加します。
dt = new Date();
ちなみに、日付のこれらのすべての方法(getSeconds、gethoursなど)は預けられます。 System.currenttimemillis()をダウンロードの開始時に実行し、最後に再び減算することで、タイミングを取得できます。これは、必要に応じて数時間/分/秒に変換できるミリ秒単位の合計期間です。
所属していません StackOverflow