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

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

问题描述

我正在开发一个应用程序,它几乎完成了,只有一件事:我不知道如何获得链接速度并将其放置在状态栏中.我是 Java 新手,所以如果有人可以帮助我,我会非常感谢.附言抱歉英语不好.

I am working on an app and it is almost finished except only one thing: I don't 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 grateful. P.S. Sorry for bad English.

推荐答案

正如回答者所说,你的问题不是很清楚.您可能指的是链接连接速度(即高达 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:

  • 对于 WiFi 链接速度检查 WifiInfo.getLinkSpeed()
  • 对于移动数据链接,恐怕您只能查看TelefonyManager.getNetworkType() 以确定当前的移动数据链路类型.然后,您应该根据链路类型来近似实际速度(即,GPRS 最高 128 kbps,EDGE 最高 236.8 kpbs,3G 最高 2 Mbps,HSDPA 最高 7.2 Mbps).考虑到这只是一个近似值.您可能使用 HSDPA 进行连接,但您的运营商将最高速度限制为 2 Mbps.
  • 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.

其他情况下,您指的是当前(下载/上传)数据链接速度,这仅在较高级别可用,实际上测量的不是链接速度,而是您的手机和手机之间的速度服务器,这不仅取决于您的链接速度,还取决于许多其他因素(您的手机与服务器之间的所有链接、服务器本身等).您可以只测量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天全站免登陆