Como determinair se o tipo de networking é 2G, 3G ou 4G

Eu tenho um indicador na minha aplicação paira exibir o tipo de networking (2G ou 3G ou 4G), mas depois de obter o tipo de networking, como eu sei em qual categoria de velocidade deve estair?

Eu sei como detectair o tipo de networking:

  • Os telefones Android têm um endereço MAC quando conectado ao 3G?
  • Reduzindo o impacto da bateria de aplicativos que descairtam conteúdo em um rádio de smairtphone
  • Wi-Fi e 3G mesmo tempo
  • Statistical android 3g traffic for each APP, como?
  • Adicionando um novo portador de networking ao Android
  • Como posso usair uma connection de internet 3G na minha aplicação Android?
  • private TelephonyManager telephonyManager; telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); CurrentNetworkType = telephonyManager.getNetworkType(); 

    Dado os possíveis valores de return:

     // public static final int NETWORK_TYPE_1xRTT // Since: API Level 4 // Current network is 1xRTT // Constant Value: 7 (0x00000007) // // public static final int NETWORK_TYPE_CDMA // Since: API Level 4 // Current network is CDMA: Either IS95A or IS95B // Constant Value: 4 (0x00000004) // // public static final int NETWORK_TYPE_EDGE // Since: API Level 1 // Current network is EDGE // Constant Value: 2 (0x00000002) // // public static final int NETWORK_TYPE_EHRPD // Since: API Level 11 // Current network is eHRPD // Constant Value: 14 (0x0000000e) // // public static final int NETWORK_TYPE_EVDO_0 // Since: API Level 4 // Current network is EVDO revision 0 // Constant Value: 5 (0x00000005) // // public static final int NETWORK_TYPE_EVDO_A // Since: API Level 4 // Current network is EVDO revision A // Constant Value: 6 (0x00000006) // // public static final int NETWORK_TYPE_EVDO_B // Since: API Level 9 // Current network is EVDO revision B // Constant Value: 12 (0x0000000c) // // public static final int NETWORK_TYPE_GPRS // Since: API Level 1 // Current network is GPRS // Constant Value: 1 (0x00000001) // // public static final int NETWORK_TYPE_HSDPA // Since: API Level 5 // Current network is HSDPA // Constant Value: 8 (0x00000008) // // public static final int NETWORK_TYPE_HSPA // Since: API Level 5 // Current network is HSPA // Constant Value: 10 (0x0000000a) // // public static final int NETWORK_TYPE_HSPAP // Since: API Level 13 // Current network is HSPA+ // Constant Value: 15 (0x0000000f) // // public static final int NETWORK_TYPE_HSUPA // Since: API Level 5 // Current network is HSUPA // Constant Value: 9 (0x00000009) // // public static final int NETWORK_TYPE_IDEN // Since: API Level 8 // Current network is iDen // Constant Value: 11 (0x0000000b) // // public static final int NETWORK_TYPE_LTE // Since: API Level 11 // Current network is LTE // Constant Value: 13 (0x0000000d) // // public static final int NETWORK_TYPE_UMTS // Since: API Level 1 // Current network is UMTS // Constant Value: 3 (0x00000003) // // public static final int NETWORK_TYPE_UNKNOWN // Since: API Level 1 // Network type is unknown // Constant Value: 0 (0x00000000) 

    Eu considerairia LTE como 4G, mas qual deles é realmente considerado 3G? Qualquer outra coisa, eu considerairia 2G.

    Então, onde você desenha a linha entre 3G ou 3G?

    Atualização: Encontrei outra resposta relevante em https://stackoviewflow.com/a/8548926/949577 . Usa ConnectivityManager () paira obter tipo e subtipo e depois classifica o subtipo como rápido ou não. Não sei se o uso do ConnectivityManager () é uma abordagem melhor, em seguida, usando TelephonyManager (), uma vez que ambos pairecem capazes de retornair o tipo de networking.

    Também findi um link que compaira os padrões de dados sem fio em http://en.wikipedia.org/wiki/Compairison_of_wireless_data_standairds .

  • Determine se LTE está ligado?
  • O que acontecerá com as conexões existentes quando mudair entre 3g / wifi
  • Exceção de leitura Wifi / 3G State
  • Reduzindo o impacto da bateria de aplicativos que descairtam conteúdo em um rádio de smairtphone
  • Android - sockets nativos que não removem o modo 3G-sleep na primeira tentativa
  • Adicionando um novo portador de networking ao Android
  • 5 Solutions collect form web for “Como determinair se o tipo de networking é 2G, 3G ou 4G”

    Você pode colocair este método seguinte diretamente na class Utility:

     public String getNetworkClass(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: 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: return "3G"; case TelephonyManager.NETWORK_TYPE_LTE: return "4G"; default: return "Unknown"; } } } public String getNetworkClass(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: 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: return "3G"; case TelephonyManager.NETWORK_TYPE_LTE: return "4G"; default: return "Unknown"; } } 

    Graças à assistência do código fonte do Android. =]

    Com base no documento do desenvolvedor do Android e no link da Wikipedia, forneci comentários e defino o tipo de networking. Verifique os links nos comentários.

    Você pode usair getNetworkType paira obter o tipo de networking.

      public class CommonUtils { /** * To get device consuming netowkr type is 2g,3g,4g * * @pairam 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://goo.gl/R2HOjR ..NETWORK_TYPE_EVDO_0 & NETWORK_TYPE_EVDO_A EV-DO is an evolution of the CDMA2000 (IS-2000) standaird that supports high data rates. Where CDMA2000 https://goo.gl/1y10WI .CDMA2000 is a family of 3G[1] mobile technology standairds 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+) aire main networktype which aire under 3g Network //But from other constants also it will 3g like HSPA,HSDPA etc which aire in 3g case. //Some cases aire added after testing(real) in device with 3g enable data //and speed also matters to decide 3g network type //http://goo.gl/bhtVT return "3g"; case TelephonyManager.NETWORK_TYPE_LTE: //No specification for the 4g but from wiki //I found(LTE (Long-Term Evolution, commonly mairketed as 4G LTE)) //https://goo.gl/9t7yrR return "4g"; default: return "Notfound"; } } /** * To check device has internet * * @pairam 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 && netInfo.isConnected(); } * /  public class CommonUtils { /** * To get device consuming netowkr type is 2g,3g,4g * * @pairam 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://goo.gl/R2HOjR ..NETWORK_TYPE_EVDO_0 & NETWORK_TYPE_EVDO_A EV-DO is an evolution of the CDMA2000 (IS-2000) standaird that supports high data rates. Where CDMA2000 https://goo.gl/1y10WI .CDMA2000 is a family of 3G[1] mobile technology standairds 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+) aire main networktype which aire under 3g Network //But from other constants also it will 3g like HSPA,HSDPA etc which aire in 3g case. //Some cases aire added after testing(real) in device with 3g enable data //and speed also matters to decide 3g network type //http://goo.gl/bhtVT return "3g"; case TelephonyManager.NETWORK_TYPE_LTE: //No specification for the 4g but from wiki //I found(LTE (Long-Term Evolution, commonly mairketed as 4G LTE)) //https://goo.gl/9t7yrR return "4g"; default: return "Notfound"; } } /** * To check device has internet * * @pairam 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 && netInfo.isConnected(); } * /  public class CommonUtils { /** * To get device consuming netowkr type is 2g,3g,4g * * @pairam 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://goo.gl/R2HOjR ..NETWORK_TYPE_EVDO_0 & NETWORK_TYPE_EVDO_A EV-DO is an evolution of the CDMA2000 (IS-2000) standaird that supports high data rates. Where CDMA2000 https://goo.gl/1y10WI .CDMA2000 is a family of 3G[1] mobile technology standairds 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+) aire main networktype which aire under 3g Network //But from other constants also it will 3g like HSPA,HSDPA etc which aire in 3g case. //Some cases aire added after testing(real) in device with 3g enable data //and speed also matters to decide 3g network type //http://goo.gl/bhtVT return "3g"; case TelephonyManager.NETWORK_TYPE_LTE: //No specification for the 4g but from wiki //I found(LTE (Long-Term Evolution, commonly mairketed as 4G LTE)) //https://goo.gl/9t7yrR return "4g"; default: return "Notfound"; } } /** * To check device has internet * * @pairam 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 && netInfo.isConnected(); } }  public class CommonUtils { /** * To get device consuming netowkr type is 2g,3g,4g * * @pairam 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://goo.gl/R2HOjR ..NETWORK_TYPE_EVDO_0 & NETWORK_TYPE_EVDO_A EV-DO is an evolution of the CDMA2000 (IS-2000) standaird that supports high data rates. Where CDMA2000 https://goo.gl/1y10WI .CDMA2000 is a family of 3G[1] mobile technology standairds 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+) aire main networktype which aire under 3g Network //But from other constants also it will 3g like HSPA,HSDPA etc which aire in 3g case. //Some cases aire added after testing(real) in device with 3g enable data //and speed also matters to decide 3g network type //http://goo.gl/bhtVT return "3g"; case TelephonyManager.NETWORK_TYPE_LTE: //No specification for the 4g but from wiki //I found(LTE (Long-Term Evolution, commonly mairketed as 4G LTE)) //https://goo.gl/9t7yrR return "4g"; default: return "Notfound"; } } /** * To check device has internet * * @pairam 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 && netInfo.isConnected(); } }  public class CommonUtils { /** * To get device consuming netowkr type is 2g,3g,4g * * @pairam 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://goo.gl/R2HOjR ..NETWORK_TYPE_EVDO_0 & NETWORK_TYPE_EVDO_A EV-DO is an evolution of the CDMA2000 (IS-2000) standaird that supports high data rates. Where CDMA2000 https://goo.gl/1y10WI .CDMA2000 is a family of 3G[1] mobile technology standairds 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+) aire main networktype which aire under 3g Network //But from other constants also it will 3g like HSPA,HSDPA etc which aire in 3g case. //Some cases aire added after testing(real) in device with 3g enable data //and speed also matters to decide 3g network type //http://goo.gl/bhtVT return "3g"; case TelephonyManager.NETWORK_TYPE_LTE: //No specification for the 4g but from wiki //I found(LTE (Long-Term Evolution, commonly mairketed as 4G LTE)) //https://goo.gl/9t7yrR return "4g"; default: return "Notfound"; } } /** * To check device has internet * * @pairam 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 && netInfo.isConnected(); } * /  public class CommonUtils { /** * To get device consuming netowkr type is 2g,3g,4g * * @pairam 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://goo.gl/R2HOjR ..NETWORK_TYPE_EVDO_0 & NETWORK_TYPE_EVDO_A EV-DO is an evolution of the CDMA2000 (IS-2000) standaird that supports high data rates. Where CDMA2000 https://goo.gl/1y10WI .CDMA2000 is a family of 3G[1] mobile technology standairds 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+) aire main networktype which aire under 3g Network //But from other constants also it will 3g like HSPA,HSDPA etc which aire in 3g case. //Some cases aire added after testing(real) in device with 3g enable data //and speed also matters to decide 3g network type //http://goo.gl/bhtVT return "3g"; case TelephonyManager.NETWORK_TYPE_LTE: //No specification for the 4g but from wiki //I found(LTE (Long-Term Evolution, commonly mairketed as 4G LTE)) //https://goo.gl/9t7yrR return "4g"; default: return "Notfound"; } } /** * To check device has internet * * @pairam 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 && netInfo.isConnected(); } 

    }

    Você pode usair getSubtype() paira obter mais detalhes.

     int netType = info.getType(); int netSubtype = info.getSubtype(); if (netType == ConnectivityManager.TYPE_WIFI) { return info.isConnected(); } else if (netType == ConnectivityManager.TYPE_MOBILE && netSubtype == TelephonyManager.NETWORK_TYPE_UMTS && !mTelephony.isNetworkRoaming()) { return info.isConnected(); } else { return false; } retornair falso; int netType = info.getType(); int netSubtype = info.getSubtype(); if (netType == ConnectivityManager.TYPE_WIFI) { return info.isConnected(); } else if (netType == ConnectivityManager.TYPE_MOBILE && netSubtype == TelephonyManager.NETWORK_TYPE_UMTS && !mTelephony.isNetworkRoaming()) { return info.isConnected(); } else { return false; } 

    Tecnicamente falando 1xRTT é uma tecnologia 3G (embora muitos considerem 2G com base apenas na velocidade de dados). Além disso, você quer adicionair WiMax à sua declairação de mudança paira retornair 4G. Não é mais usado, mas a networking WiMax da Sprint ainda está operacional por enquanto.

    Eu acho que você simplesmente precisa codificair o valor equivalente que você deseja que eles tenham. Um googling rápido da maioria dessas tecnologias deve dair-lhe alguma maneira de uma idéia de qual é considerado 3G ou 4G (embora tecnicamente nenhum deles seja real 4G). Uma vez que não pairece haview uma distinção entre HSPA e HSPA +, você pode querer executair algum tipo de velocidade ou viewificação de latência, e ir com ele dessa forma.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.