如何获得链接速度编程? [英] How to get link speed programmatically?

查看:126
本文介绍了如何获得链接速度编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的应用程序,它几乎finnished exept的只有一件事:我不知道怎么去链接速度,并将其放置在状态bar.I是新来的Java所以,如果有人可以帮助我,我将非常感激。 附:对不起,我的英语很差。

I am working on app and it is almost finnished exept only one thing: i dont know how to get link speed and place it in the status bar.I am new to Java so if somebody could help me i would be very greatful. P.S. Sorry for bad English.

推荐答案

随着repliers建议,你的问题不是很清楚。您可以参考链路连接速度(即高达54 Mbps,具有良好的信号接收Wifi或高达7.2 Mbps的全速HSDPA),这取决于:

As the repliers suggest, your question is not very clear. You could be referring to the link connection speed (i.e up to 54 Mbps with good signal reception Wifi or up to 7.2 Mbps with full speed HSDPA) which depends on:

  • 您使用的是每一次的网络接口的。有些手机允许圈养,这意味着你可以同时拥有WiFi和移动数据连接(GPRS / 3G / HSDPA)活跃在同一时间,或自动开关(如果您的WiFi连接断开你的手机会自动切换到移动网络中,如果已激活)。
  • 谈判的时间的连接速度的。根据信号质量/运营商网络配置(部分有最大限速)/移动数据合同(每月带宽超过配额,通常是指默认为GPRS的速度)。
  • The network interface you are using at a time. Some phones allow tethering which means you can have both Wifi and Mobile Data Link (GPRS/3G/HSDPA) active at the same time, or on automatic switch (if your Wifi connection drops your phone will switch to Mobile network automatically if activated).
  • The connection speed negotiated at a time. Depending on signal quality/carrier network configuration (some have max. speed limited)/mobile data contract (monthly bandwith quota exceeded normally means defaulting to GPRS speed).

在这种情况下,恐怕没有一个标准的Java API方法来知道它,但Android的API所需的功能:

In this case I am afraid there is no standard Java API methods to know it, but the Android API the needed functionality:

  • 对于无线网络链接速度检查 WifiInfo.getLinkSpeed ()
  • 在移动数据链接恐怕您只能检查<一href="http://developer.android.com/reference/android/telephony/TelephonyManager.html#getNetworkType%28%29"相对=nofollow> TelefonyManager.getNetworkType()以确定当前移动数据链路类型。然后,您应该aproximate通过链接类型实际速度(即GPRS的高达128 Kbps,对于EDGE达236.8 KPBS,为3G高达2 Mbps,支持HSDPA高达7.2 Mbps的)。考虑到这只是一个aproximation 。您可以使用HSDPA可以conneting但运营商限制最高速度为2Mbps的。
  • For WiFi link speed check WifiInfo.getLinkSpeed()
  • For Mobile Data Link I am afraid that you can only check TelefonyManager.getNetworkType() to determine the current Mobile Data Link type. You should then aproximate to actual speed by link type (i.e. for GPRS up to 128 kbps, for EDGE up to 236.8 kpbs, for 3G up to 2 Mbps, for HSDPA up to 7.2 Mbps). Take into consideration that this is only an aproximation. Your could be conneting using HSDPA but your carrier limiting the top speed to 2 Mbps.

在您参考当前(下载/上传)数据链路速度在另一种情况这是只可在一个较高的水平,实际测量而不是链接速度,但在手机和之间的速度服务器,它不仅可以通过你的链接速度,还受许多其他因素来determinted(手机之间的服务器,服务器本身等所有环节)。你可以只测量HTTP平飞速度,这意味着HTTP数据速率(省去开销流量的数据包),因为通常只有HTTP连接在每个场景中的支持(您的运营商可能藏匿在你身后的代理能过滤所有的东西,但HTTP交通)。

In the other case that you refer the current (Download/Upload) data link speed this is only available at a high level, actually measuring not the link speed but the speed between your phone and a server, which can be determinted not only by your link speed but also by many other factors (all the links between your phone an server, the server itself, etc.). You could just measure "HTTP level speed" which means HTTP data speed (leaving out overhead traffic for data packets), since normally only HTTP connections are supported in every scenario (your carrier could be hiding you behind a proxy that filters everything out but HTTP traffic).

如果您使用的是8级API,称为一个有趣的功能 TrafficStats 也可以。这可以让你知道的发送/接收的数据包在较低的水平上移动数据链路交换的手机,这可能只提供您要寻找的内容(使用这些测量随时间变化的信息,并可以很容易地测量电流/平均使用的数据链接速度)。

If you are using 8 level API an interesting feature called TrafficStats is also available. This lets you know the sent/received packets at a low level exchanged by your phone over the Mobile Data Link, which may offer just the information you where looking for (use these measurements with elapsed times and you can easily measure current/average used data link speed).

这篇关于如何获得链接速度编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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