如何在android中找到GPRS/3G网络数据传输速度?

发布于 2024-11-01 20:28:21 字数 81 浏览 7 评论 0原文

在我的应用程序中,我需要找到连接网络的速度(wifi/GPRS/3G)。在这里我需要帮助来确定 GPRS/3G 网络的速度。你能帮我解决这个问题吗?

in my application i need to find the speed of connected network (wifi/GPRS/3G). Here i need help to find the speed of GPRS/3G network. Can you please help me how to solve this problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

虐人心 2024-11-08 20:28:21

这也不是一个完整的答案,但对于 Wifi 网络(非蜂窝网络),您可以通过以下方式获取链接速率:

public String getLinkRate() 
{
    WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
    WifiInfo wi = wm.getConnectionInfo();
    return String.format("%d Mbps", wi.getLinkSpeed());
}

需要注意的一些事项:

  1. 这将需要 android.permission.ACCESS_WIFI_STATE 权限。
  2. 它始终是 802.11 标准指定的速率之一(请参阅此处的表格)
  3. 这只是手机和AP协商的最大速率。许多因素都会影响您在网上冲浪时获得的实际速率(例如无线拥塞和冲突、上行链路速率)

This isn't a complete answer either, but for Wifi networks (not cellular), you can get the link rate through something like the following:

public String getLinkRate() 
{
    WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
    WifiInfo wi = wm.getConnectionInfo();
    return String.format("%d Mbps", wi.getLinkSpeed());
}

A few things to note:

  1. This will require the android.permission.ACCESS_WIFI_STATE permission.
  2. It will always be one of the rates specified by the 802.11 standard (see the table here)
  3. It is only the rate that the handset and AP have negotiated as the maximum rate. A lot of factors come into play that affect the actual rate you'd get while, say surfing the web (e.g. wireless congestion and collisions, the upstream link rate)
瀟灑尐姊 2024-11-08 20:28:21

TrafficStats 将完成这项工作。您可以获取传输的字节数,然后可以计算速度。

TrafficStats will do the work. You can get bytes transferred, then you can calculate the speed.

鱼忆七猫命九 2024-11-08 20:28:21

也许可以弄清楚,该用户已连接到 wifi、gprs 或 g3 网络。
然后你就可以算出每种技术的速度有多快。您也可以将文件(例如 3MB)放在快速连接服务器上。然后您可以下载该文件并测量时间,即需要多长时间。然后只需计算...或者您可以在文件下载时每秒计算一次。

此外,下载速度可能因不同条件而异。比如网络强度(展位无线和移动)。例如,如果用户连接到 54mbit wifi,并且接入点距用户 60 米,那么下载速度甚至不会是其一半。
这是下载速度计算的示例 java 如何计算 Mbit/s while循环下载

maybe it is possible to figure out, that user is connected to wifi, gprs, or g3 network.
Then you can figure out how fast is each technology. Also you can put file (for example 3MB) on fast connection server. Then you can download that file and measure time, how long it takes. Then just calculate... Or You can calculate it after each second while file is downloading.

Also download speed may vary from various conditions. Like network strength (booth wireless and mobile). For example, if user is connected to 54mbit wifi and access point is 60 meters form user, then download speed wont be even half of that.
Here is example with download speed calculations java howto calculate Mbit/s during while loop download

虚拟世界 2024-11-08 20:28:21

看看 Zwitscher NetworkHelper 类

基本上你需要获取ConnectivityManager

cManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

,然后查询您想了解的内容。

NetworkInfo info = cManager.getActiveNetworkInfo();
int type = info.getType();
int subType = info.getSubtype();

有关详细信息,请浏览上面的类以查看 typesubType 的含义。

Have a look at Zwitscher's NetworkHelper class

Basically you need to obtain the ConnectivityManager

cManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

and then query this for what you want to know

NetworkInfo info = cManager.getActiveNetworkInfo();
int type = info.getType();
int subType = info.getSubtype();

For more info, browse the above class to see the meanings of type and subType.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文