有没有一种方法来检测2G,3G或4G的Android设备? [英] Is there a way to detect 2G, 3G, or 4G on Android Device?
问题描述
我的应用程序将提供现场视频流。我想知道是否有一种方法来检测用户是否有2G,3G,或4G在他们的设备,并且如果哪个类别当前连接属于?我的问题是专门关于Android设备。
我不知道的方式来查询设备的硬件功能(该电台是present),但如果你问如何检测蜂窝数据连接的当前类型,期待<一个href="http://developer.android.com/reference/android/telephony/TelephonyManager.html#getNetworkType%28%29"><$c$c>TelephonyManager.getNetworkType()$c$c>,其中返回一个常量指示无线电技术(网络类型)的当前使用的设备进行数据传输中的
我会考虑的数值 NETWORK_TYPE_LTE
和 NETWORK_TYPE_HSPAP
来表示一个4G连接。由于3G与4G之间的界线是模糊的,并且由于一套旧技术被有效地固定(我们没有发明新的2G网络),一个更好的策略可能是识别是的没有的足够的网络技术并显示警告,如果连接是使用已知的技术慢(例如,EDGE)。
另外请记住,网络技术本身并不一定等同于一定的连接速度。甚至一个4G连接可以在速度是不够的视频流这取决于许多因素,其中一些外部的设备运行(天气,信号强度,装置的电池水平,可用带宽在小区塔等)对>
其他注意事项:
-
您应该首先检查活动的网络连接是否蜂窝连接。要做到这一点,得到<一href="http://developer.android.com/reference/android/net/ConnectivityManager.html#getActiveNetworkInfo%28%29"><$c$c>ConnectivityManager.getActiveNetworkInfo()$c$c>并检查对象的<一个href="http://developer.android.com/reference/android/net/NetworkInfo.html#getType%28%29"><$c$c>getType()$c$c>.这表明当前网络是否是Wi-Fi或蜂窝。请记住,有可能是没有活动网络(
空
将被退回)。 -
您也应该检查<一href="http://developer.android.com/reference/android/net/ConnectivityManager.html#isActiveNetworkMetered%28%29"><$c$c>ConnectivityManager.isActiveNetworkMetered()$c$c>一个有关当前网络连接是否具有数据限制的提示。如果是这样,你应该提醒在执行数据密集型运算无论连接类型,然后用户。
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.
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".
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).
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.)
Other caveats:
You should first check whether the active network connection is a cellular connection. To do this, get
ConnectivityManager.getActiveNetworkInfo()
and examine that object'sgetType()
. This will indicate whether the active network is Wi-Fi or cellular. Keep in mind that there may be no active network (null
will be returned).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.
这篇关于有没有一种方法来检测2G,3G或4G的Android设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!