N-JOY
N-JOY

Reputation: 7635

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. total bytes or connection time etc.

Upvotes: 2

Views: 468

Answers (2)

Aman Aalam
Aman Aalam

Reputation: 11251

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.

It's still what I think, maybe better options are available.

Upvotes: 1

George
George

Reputation: 3817

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

Upvotes: 3

Related Questions