开发者

How to calculate website speed in Android

How can I calculate the website speed in Android, in other words how soon it will open up in browser. I also wish to calculate all the statistics of that particular page e.g. t开发者_如何转开发otal bytes or connection time etc.


You could:

  1. save the current timestamp,
  2. make a http request,
  3. get the http response,
  4. and get the timestamp as soon as your response arrives and calculate the difference in time.

Or, you could

  1. Create a WebView
  2. Set a WebViewClient
  3. Use its callbacks - onPageLoaded, onPageFinished, onPageStarted, etc ...

Check here: http://developer.android.com/reference/android/webkit/WebViewClient.html


The logic may not be very accurate, but this is what I think:

  • You open an HttpConnection to that website.
  • Take the current time-stamp somewhere in any variable
  • From that HttpConnection, start reading the contents of the website, and store it all into a string variable
  • Again take current time-stamp somewhere

Now, Analysis:

  • The difference between both the time-stamps is the time that it takes to open that website based on the current speed.
  • The size of the String variable you downloaded the whole content is the size of the home-page of that website
  • size/time taken is your current internet speed

This might not work accurately in some situations, like when the URLs are being redirected, i guess.

Its still what I think, maybe better options are available.

Hope it helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜