开发者

android data transfer rate

how to find out the data transfer r开发者_JAVA技巧ate while sending and recieving the data from server in android application.


You could add some code within your download/upload code such as for instance:

InputStream is = ...;
long totalBytesRead = 0;
long bytesRead = 0;
long startTime = System.currentTimeMillis();

while ((bytesRead = is.read(...))!=0) {
    // Do something useful with the bytes you read

    totalBytesRead += bytesRead;
}

long endTime = System.currentTimeMillis();
float dataRate1 = totalBytesRead / (float) (endTime - startTime); // Bytes/Millisecond
float dataRate2 = dataRate1 * 1000 / 1024.0f; // kiloBytes/second

Of course, you could also update periodically the transfer rate within you while loop to get an average rate during the progress.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜