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.
Share
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_LTEandNETWORK_TYPE_HSPAPto 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 (nullwill 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.