使用 NetworkCapability 类在 Android 中获取上传和下载带宽

Pau*_*Sen 3 android bandwidth

我正在开发一个小型视频流应用程序。我想获取Android中网络的上传和下载速度。我发现我们可以通过使用Android NetworkCapability类提供的功能来做到这一点

getLinkDownstreamBandwidthKbps()
Retrieves the downstream bandwidth for this network in Kbps. 
This always only refers to the estimated first hop transport bandwidth.

getLinkUpstreamBandwidthKbps ()
Retrieves the upstream bandwidth for this network in Kbps. 
This always only refers to the estimated first hop transport bandwidth.
Run Code Online (Sandbox Code Playgroud)

1.这里的第一跳是什么意思?

2.如何使用它们。请提供一些链接供参考,我们如何使用它们?

Mim*_*oli 5

如果您处于活动中,您可以通过以下方式获取信息:

ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
Network[] networks = cm.getAllNetworks();
...cycle or choose a network...
NetworkCapabilities capabilities = cm.getNetworkCapabilities(network);
Run Code Online (Sandbox Code Playgroud)

第一跳意味着它是对链接功能的估计,而不是对流量通过网络路由到达端点时获得的带宽的估计。请注意,此方法可从 Lollipop 获得。