检查机器人的带宽速率速率、机器人、带宽

2023-09-12 22:52:02 作者:PawN

我们有一个选项来检查网络连接类型的机器人(无论是3G,EDGE或GPRS)。

We have an option to check the network connection types in android ( whether it is 3G , edge or gprs) .

我需要检查的带宽速率。我需要initaite呼叫。对于我需要检查带宽速率..Above只有我需要看到一个选项,用于调用特定badnwidth(发起呼叫 )。因此,如何检查的带宽速率。

I need to check the the bandwidth rate .I need to initaite a call.. For that i need to check the bandwidth rate ..Above a particular badnwidth only i need to make visible an option for a call( to initiate a call ). So how to check the bandwidth rate.

我需要的编程找到的连接速度(连接速度的移动数据连接,EDGE) ...请帮助

i need to find the connection speed programmatically(connection speed for Mobile Data Link , EDGE)...Please help

推荐答案

您可以从服务器上下载一个已知大小的文件,并计算出它没多长时间才能下载。然后你有你的带宽。简单,但工程:)

You can download a known-size file from your server, and calculate how long did it take to download it. Then you have your bandwidth. Simple but works :)

样品,没有测试:

//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);
 
精彩推荐
图片推荐