检查Android中的带宽率

问题描述 投票:12回答:3

我们可以选择检查Android中的网络连接类型(无论是3G,边缘还是gprs)。

我需要检查带宽率。我需要发起一个电话。为此,我需要检查带宽率。仅在特定带宽之上,我需要为呼叫提供可见选项(以发起呼叫)。

我需要以编程方式找到连接速度(Mobile Data Link,EDGE的连接速度)。

android bandwidth codec
3个回答
17
投票

您可以从服务器下载已知大小的文件,并计算下载它所需的时间。然后你有你的带宽。简单但有效:)

样品,未测试:

//Download your image
long startTime = System.currentTimeMillis();
HttpGet httpRequest = new HttpGet(new URL(urlString).toURI());
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpClient.execute(httpRequest);
long endTime = System.currentTimeMillis();

HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity;
bufHttpEntity = new BufferedHttpEntity(entity);

//You can re-check the size of your file
final long contentLength = bufHttpEntity.getContentLength();

// Log
Log.d(TAG, "[BENCHMARK] Dowload time :"+(endTime-startTime)+" ms");

// Bandwidth : size(KB)/time(s)
float bandwidth = contentLength / ((endTime-startTime) *1000);

7
投票

这将返回LINK_SPEED_UNITS.中的当前链接速度

但这对WIFI Only来说很有用

WifiManager wifiManager = Context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
    Integer linkSpeed = wifiInfo.getLinkSpeed(); //measured using WifiInfo.LINK_SPEED_UNITS
}

0
投票

试试facebook网络库类(库大小= 16 KB)

我们也可以手动获取/网络更改侦听器。

手动获取代码:

ConnectionQuality cq = ConnectionClassManager.getInstance()。getCurrentBandwidthQuality();

Github链接 - https://github.com/facebook/network-connection-class

© www.soinside.com 2019 - 2024. All rights reserved.