How detect networktype (2G/3G/LTE) when connected to WiFi

I'm currently writing an app where I want to detect which network type (2G, 3G or LTE) an Android device is currently connected to. I have tried using the following solutions:

TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 
tm.getNetworkType()

and Connectivitymanager:

ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getSubtype() 

Both methods work fine without WiFi connection but if connected to a WiFI TelephonyManager returns https://developer.android.com/reference/android/telephony/TelephonyManager#NETWORK_TYPE_IWLAN and ConnectivityManager returns 0 (UNKNOWN).

Is there any way to find out if a phone is connected to 2G, 3G or LTE even if it is connected to a WiFi network?


The issue was that in API-version 24 and forward getNetworkType() has been split in into two separate methods:

getDataNetworkType()

and

getVoiceNetworkType()

I added a check in my code to se if the returned type was IWLAN and if so use getVoiceNetworkType() instead.

if (tm.getNetworkType() != 18)
    return tm.getNetworkType();
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) 
    return tm.getVoiceNetworkType();
else 
    return -1;

How to detect if the conection is 2G, 3G, 4G or WIFI , JavaScripts has a library that allows you to get the type of connection that a But​, I made a small trick, because the difference between 2G, 3G and 4G is you need allcellinfo , and parse the network type - Gsm Wcdma or Lte FEATURES: CARRIER INFO • Detect current connected mobile network operator name, country, region. • Show the carrier identification MCC and MNC codes. • Detect current cellular connection mode (GPRS, EDGE, UMTS, HSPA, LTE). • Detect LTE operation bands supported by your carrier.


You could try using getAllNetworks() from ConnectivityManager which tracks all active networks.

See here: https://developer.android.com/reference/android/net/ConnectivityManager#getAllNetworks()

You can retrieve more detailed information on a certain returned network with getNetworkInfo()

See here: https://developer.android.com/reference/android/net/ConnectivityManager#getNetworkInfo(android.net.Network)

How to Detect Connection type (2g,3g,4g,Wifi) for Android , Detect Android Data Connection type 2g, 3g, 4g or Wifi. If you want to check what state of your Android Network Device, you can get it using  Today we are here with the cool trick to Find Devices Connected To Wifi Network.Lots of people now use wifi, and almost everyone has their personal wifi networks. However, sometimes other person knows your password and can use your wifi network, and with that, your bandwidths get divided, and your network speed ge


call this method

public void checkNetworkType(){
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

        if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSDPA)) {

            Toast.makeText(this, "3G network type", Toast.LENGTH_LONG).show();


        } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSPAP)) {
            Toast.makeText(this, "4G network type", Toast.LENGTH_LONG).show();

        } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_GPRS)) {
            Toast.makeText(this, "GPRS network type", Toast.LENGTH_LONG).show();

        } else if ((tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE)) {
            Toast.makeText(this, "2G network type", Toast.LENGTH_LONG).show();

        }
    }

How to know if the internet in my phone is 2G, 3G or 4G, It is used in the GSM i.e Global System for Mobile or we can simply say 2G. easiest method to determine whether your phone is connected to 2G, 3G, or 4G / LTE: network type besides the Signal area of mobile phone(G for GPRS(2G),E for of movement to 5g networks that will challenger current wireless wifi speeds​. the specific 802.11 protocol it runs, the strength of its device transmitter, and. the nature of physical obstructions and radio interference in the surrounding area—physical obstructions in homes such as brick walls and metal frames or siding reduce the range of a Wi-Fi network by 25 percent or more.


RTCNetworkType, identify the type of network used by a connection between two peers. This includes all cellular data services including EDGE (2G), HSPA (3G), LTE (4G), For example, if the networkType is wifi but the user is connected  In this guide, we'll show you everything you need to know to manage wireless network connections on Windows 10 using the Settings app. How to manage wireless network connections on Windows 10


Performance of Wireless Networks: Mobile Networks, Data rates and latency for an active mobile connection How do you know which network type your carrier is using? Simple. Interoperable with previous wireless standards (3G and 2G) For this reason, LTE (release 8) and most HSPA+ networks, which do not meet the actual technical 4G requirements, are nonetheless  Hi, I can find the network is wifi or cellular but I need more detail, such as E,3G,4G/lte .. I havent seen any solution .. there are 2 classes that I saw i can use but no sample available


Network, APN, and VoLTE: T-Mobile REVVL, On this page:APN & data settingsManual network selectionSwitch 2G / 4GTurn on The device detects and registers on wireless networks inside T-Mobile's calling Tap Cellular networks > Preferred network type. LTE On (Automatic LTE/3G/2G); LTE Off (Automatic 3G/2G); LTE/3G; 2G only Apps & connected devices. Connect the Wireless DIRECTV CINEMA Connection Kit device to the receiver. Within one minute the message Connection has been detected appears on the TV. Follow the steps in the article Set up your Wireless DIRECTV CINEMA Connection Kit if you need help. Use the DIRECTV remote control to select Set Up Now on the TV.