检查Android中的带宽率

jen*_*fer 12 android bandwidth codec

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

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

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

Cam*_*e R 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);
Run Code Online (Sandbox Code Playgroud)

  • BTW这也是以编程方式 (8认同)
  • 文件越大,测试就越精确,但显然时间也最长。在我看来,一个好的折衷方案是 50KB。 (2认同)

Mor*_*ory 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
}
Run Code Online (Sandbox Code Playgroud)

  • 此外,该方法仅返回当前关联的Wi-Fi AP的理论最大链路速度,对于大多数AP,通常为54 mbps. (6认同)
  • 我需要检查Mobile Data Link的连接速度(主要是EDGE) (4认同)