检查机器人的带宽速率 [英] Check the bandwidth rate in Android

查看:163
本文介绍了检查机器人的带宽速率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个选项来检查网络连接类型的机器人(无论是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);

这篇关于检查机器人的带宽速率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆