I want to get Network Connection Bandwidth in kbps or mbps. if the device is connected to wifi then it should returns the network bandwidth(speed) as well as mobile data.
it will returns wifi capablity rate but i want exact data transfer rate.
public String getLinkRate()
{
WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
WifiInfo wi = wm.getConnectionInfo();
return String.format("%d Mbps", wi.getLinkSpeed());
}
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 an
AsyncTask
or a worker thread, will download a remote file and return the speed in which the file was downloaded in Kbps.