在android中确定互联网速度

时间:2013-05-02 08:58:32

标签: android monitor bandwidth

我正在开发一个Android视频流应用程序,我必须检测网速,以便根据速度调整我的流质量。

我在网上搜索了如何检测android中的互联网速度,但我发现只有一种方法可以下载文件并知道其大小来确定带宽:

 bandwidth = contentLength / ((endTime-startTime) *1000);

有没有其他可能的方法来确定Android中的互联网带宽而不下载任何文件我不想通过额外的文件下载打扰我的视频流

感谢。

1 个答案:

答案 0 :(得分:1)

如果您使用的是2G,3G,4G,我不认为有一种标准的查找方式,也许您可​​以自动假设2G,3G或4G速度很慢。

如果您使用的是wifi,那么您可以计算网速 使用 WifiManager class

  

WifiInfo wifiInformation = wifiManger.getConnectionInfo();

然后从WifiInfo中获取当前速度:

  

int speedInMbpsSpeed = wifiInformation.getLinkSpeed();