Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Based on the Android Developer document &amp; Wikipedia link here i have given comments &amp; define network type.Check the links in comment.</p> <p>You can use <code>getNetworkType</code> to get Network type. </p> <pre><code> public class CommonUtils { /** * To get device consuming netowkr type is 2g,3g,4g * * @param context * @return "2g","3g","4g" as a String based on the network type */ public static String getNetworkType(Context context) { TelephonyManager mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); int networkType = mTelephonyManager.getNetworkType(); switch (networkType) { case TelephonyManager.NETWORK_TYPE_GPRS: case TelephonyManager.NETWORK_TYPE_EDGE: case TelephonyManager.NETWORK_TYPE_CDMA: case TelephonyManager.NETWORK_TYPE_1xRTT: case TelephonyManager.NETWORK_TYPE_IDEN: return "2g"; case TelephonyManager.NETWORK_TYPE_UMTS: case TelephonyManager.NETWORK_TYPE_EVDO_0: case TelephonyManager.NETWORK_TYPE_EVDO_A: /** From this link https://en.wikipedia.org/wiki/Evolution-Data_Optimized ..NETWORK_TYPE_EVDO_0 &amp; NETWORK_TYPE_EVDO_A EV-DO is an evolution of the CDMA2000 (IS-2000) standard that supports high data rates. Where CDMA2000 https://en.wikipedia.org/wiki/CDMA2000 .CDMA2000 is a family of 3G[1] mobile technology standards for sending voice, data, and signaling data between mobile phones and cell sites. */ case TelephonyManager.NETWORK_TYPE_HSDPA: case TelephonyManager.NETWORK_TYPE_HSUPA: case TelephonyManager.NETWORK_TYPE_HSPA: case TelephonyManager.NETWORK_TYPE_EVDO_B: case TelephonyManager.NETWORK_TYPE_EHRPD: case TelephonyManager.NETWORK_TYPE_HSPAP: //Log.d("Type", "3g"); //For 3g HSDPA , HSPAP(HSPA+) are main networktype which are under 3g Network //But from other constants also it will 3g like HSPA,HSDPA etc which are in 3g case. //Some cases are added after testing(real) in device with 3g enable data //and speed also matters to decide 3g network type //https://en.wikipedia.org/wiki/4G#Data_rate_comparison return "3g"; case TelephonyManager.NETWORK_TYPE_LTE: //No specification for the 4g but from wiki //I found(LTE (Long-Term Evolution, commonly marketed as 4G LTE)) //https://en.wikipedia.org/wiki/LTE_(telecommunication) return "4g"; default: return "Notfound"; } } /** * To check device has internet * * @param context * @return boolean as per status */ public static boolean isNetworkConnected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); return netInfo != null &amp;&amp; netInfo.isConnected(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload