有没有一种方法可以检测Android使用哪个蜂窝网络? [英] Is there a way to detect which cellular network is used on Android?

查看:228
本文介绍了有没有一种方法可以检测Android使用哪个蜂窝网络?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用将提供实时视频流.我想知道是否有一种方法可以检测用户的设备上是否有2G,3G或4G,以及当前连接属于哪个类别?我的问题专门针对Android设备.

My app will feature live video streams. I would like to know if there is a way to detect if the user has 2G, 3G, or 4G on their devices, and if the which category the current connection belongs to? My question is specifically about Android devices.

推荐答案

我不知道查询设备硬件功能(存在哪些无线电)的方法,但是如果您要询问如何检测当前类型的蜂窝数据连接,请查看 TelephonyManager.getNetworkType() ,返回一个常量,指示用于数据传输的设备上当前正在使用的无线电技术(网络类型)".

I'm not aware of a way to query the hardware capabilities of the device (which radios are present), but if you're asking how to detect the current type of cellular data connection, look to TelephonyManager.getNetworkType(), which "returns a constant indicating the radio technology (network type) currently in use on the device for data transmission".

我认为值NETWORK_TYPE_LTENETWORK_TYPE_HSPAP表示4G连接.由于3G和4G之间的界限很模糊,并且由于较旧的技术集已经有效地固定了(我们没有发明新的2G网络),因此,更好的策略可能是识别不足以解决问题的网络技术如果连接使用的是已知的慢速技术(例如EDGE),则会显示警告.

I would consider the values NETWORK_TYPE_LTE and NETWORK_TYPE_HSPAP to indicates a 4G connection. Since the line between 3G and 4G is blurry, and since the set of older technologies is effectively fixed (we aren't inventing new 2G networks), a better strategy may be identifying network technologies that are not sufficient and displaying a warning if the connection is using a known slow technology (e.g., EDGE).

还请记住,仅网络技术并不一定等于一定的连接速度.即使是4G连接,其运行速度也无法满足视频流的传输速度,具体取决于许多因素,其中一些因素是设备外部的因素(天气,信号强度,设备电池电量,手机信号塔处的可用带宽等)

Also keep in mind that network technology alone doesn't necessarily equate to a certain connection speed. Even a 4G connection can run at speeds that are insufficient for video streaming depending on many factors, some of which are external to the device (weather, signal strength, device battery level, bandwidth available at the cell tower, etc.)

其他警告:

您还应该检查 ConnectivityManager.isActiveNetworkMetered() 有关当前网络连接是否有数据限制的提示.如果是这样,则无论连接类型如何,都应在执行数据密集型操作之前警告用户.

You should also check ConnectivityManager.isActiveNetworkMetered() for a hint about whether the current network connection has a data restriction. If so, you should warn the user before performing data-intensive operations regardless of the connection type.

这篇关于有没有一种方法可以检测Android使用哪个蜂窝网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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