i am working on an android application where i need to play find the connection's bandwidth at run time. i found out a solution on stack overflow itself saying that i can download a file from server and then by calculating size vs time , i can get the speed of connection.
Check the bandwidth rate in Android
Is this the best way (only way) to get accurate results ? Thanks for sharing knowledge.
You can't just query for this information. Your Internet speed is determined and controlled by your
ISP
, not by your network interface or router.So the only way you can get your (current) connection speed is by downloading a file from a close enough location and timing how long it takes to retrieve the file. For example:
This code, when sightly modified (you need
mContext
to be a valid context) and executed from inside anAsyncTask
or a worker thread, will download a remote file and return the speed in which the file was downloaded in Kbps.