Java Code Examples for android.telephony.TelephonyManager#NETWORK_TYPE_CDMA

The following examples show how to use android.telephony.TelephonyManager#NETWORK_TYPE_CDMA . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetWorkUtils.java    From DevUtils with Apache License 2.0 7 votes vote down vote up
/**
 * 获取移动网络连接类型
 * <pre>
 *     {@link TelephonyManager#getNetworkClass} hide 方法
 * </pre>
 * @param networkType {@link TelephonyManager#getNetworkType}
 * @return 0 = 未知, 1 = 2G, 2 = 3G, 3 = 4G, 4 = 5G
 */
public static int getNetworkClass(final int networkType) {
    switch (networkType) {
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_GSM:
        case TelephonyManager.NETWORK_TYPE_EDGE:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_IDEN:
            return 1;
        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:
        case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
            return 2;
        case TelephonyManager.NETWORK_TYPE_LTE:
        case TelephonyManager.NETWORK_TYPE_IWLAN:
        case 19: // TelephonyManager.NETWORK_TYPE_LTE_CA
            return 3;
        case TelephonyManager.NETWORK_TYPE_NR:
            return 4;
        default:
            return 0;
    }
}
 
Example 2
Source File: CellularDrawer.java    From meter with Apache License 2.0 6 votes vote down vote up
protected String getNetworkType(){
    switch (tManager.getNetworkType()) {
        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";
    }
}
 
Example 3
Source File: Util.java    From tracker-control-android with GNU General Public License v3.0 5 votes vote down vote up
public static String getNetworkGeneration(int networkType) {
    switch (networkType) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EDGE:
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_IDEN:
        case TelephonyManager.NETWORK_TYPE_GSM:
            return "2G";

        case TelephonyManager.NETWORK_TYPE_EHRPD:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
        case TelephonyManager.NETWORK_TYPE_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_HSPAP:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_UMTS:
        case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
            return "3G";

        case TelephonyManager.NETWORK_TYPE_LTE:
        case TelephonyManager.NETWORK_TYPE_IWLAN:
            return "4G";

        default:
            return "?G";
    }
}
 
Example 4
Source File: Cell.java    From AIMSICDL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get a human-readable string of RAT/Network Type
 *
 * Frustratingly it looks like the app uses RAT & Network Type interchangably with both either
 * being an integer representation (TelephonyManager's constants) or a human-readable string.
 *
 * @param netType The integer representation of the network type, via TelephonyManager
 * @return Human-readable representation of network type (e.g. "EDGE", "LTE")
 */
public static String getRatFromInt(int netType) {
    switch (netType) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
            return "1xRTT";
        case TelephonyManager.NETWORK_TYPE_CDMA:
            return "CDMA";
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return "EDGE";
        case TelephonyManager.NETWORK_TYPE_EHRPD:
            return "eHRPD";
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
            return "EVDO rev. 0";
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
            return "EVDO rev. A";
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            return "EVDO rev. B";
        case TelephonyManager.NETWORK_TYPE_GPRS:
            return "GPRS";
        case TelephonyManager.NETWORK_TYPE_HSDPA:
            return "HSDPA";
        case TelephonyManager.NETWORK_TYPE_HSPA:
            return "HSPA";
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            return "HSPA+";
        case TelephonyManager.NETWORK_TYPE_HSUPA:
            return "HSUPA";
        case TelephonyManager.NETWORK_TYPE_IDEN:
            return "iDen";
        case TelephonyManager.NETWORK_TYPE_LTE:
            return "LTE";
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return "UMTS";
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            return "Unknown";
        default:
            return String.valueOf(netType);
    }
}
 
Example 5
Source File: NetworkUtil.java    From RetrofitClient with Apache License 2.0 5 votes vote down vote up
/**
 * is2G
 * @param context
 * @return boolean
 */
public static boolean is2G(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetInfo != null
            && (activeNetInfo.getSubtype() == TelephonyManager.NETWORK_TYPE_EDGE
            || activeNetInfo.getSubtype() == TelephonyManager.NETWORK_TYPE_GPRS || activeNetInfo
            .getSubtype() == TelephonyManager.NETWORK_TYPE_CDMA)) {
        return true;
    }
    return false;
}
 
Example 6
Source File: NetWorkHelper.java    From LLApp with Apache License 2.0 5 votes vote down vote up
private static boolean isFastMobileNetwork(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    switch (telephonyManager.getNetworkType()) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
            return false; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_CDMA:
            return false; // ~ 14-64 kbps
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return false; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
            return true; // ~ 400-1000 kbps
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
            return true; // ~ 600-1400 kbps
        case TelephonyManager.NETWORK_TYPE_GPRS:
            return false; // ~ 100 kbps
        case TelephonyManager.NETWORK_TYPE_HSDPA:
            return true; // ~ 2-14 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPA:
            return true; // ~ 700-1700 kbps
        case TelephonyManager.NETWORK_TYPE_HSUPA:
            return true; // ~ 1-23 Mbps
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return true; // ~ 400-7000 kbps
        case TelephonyManager.NETWORK_TYPE_EHRPD:
            return true; // ~ 1-2 Mbps
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            return true; // ~ 5 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            return true; // ~ 10-20 Mbps
        case TelephonyManager.NETWORK_TYPE_IDEN:
            return false; // ~25 kbps
        case TelephonyManager.NETWORK_TYPE_LTE:
            return true; // ~ 10+ Mbps
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            return false;
        default:
            return false;
    }
}
 
Example 7
Source File: NetworkChangeNotifierAutoDetect.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the connection type for the given ConnectivityManager type and subtype.
 */
@ConnectionType
private static int convertToConnectionType(int type, int subtype) {
    switch (type) {
        case ConnectivityManager.TYPE_ETHERNET:
            return ConnectionType.CONNECTION_ETHERNET;
        case ConnectivityManager.TYPE_WIFI:
            return ConnectionType.CONNECTION_WIFI;
        case ConnectivityManager.TYPE_WIMAX:
            return ConnectionType.CONNECTION_4G;
        case ConnectivityManager.TYPE_BLUETOOTH:
            return ConnectionType.CONNECTION_BLUETOOTH;
        case ConnectivityManager.TYPE_MOBILE:
            // Use information from TelephonyManager to classify the connection.
            switch (subtype) {
                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 ConnectionType.CONNECTION_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 ConnectionType.CONNECTION_3G;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return ConnectionType.CONNECTION_4G;
                default:
                    return ConnectionType.CONNECTION_UNKNOWN;
            }
        default:
            return ConnectionType.CONNECTION_UNKNOWN;
    }
}
 
Example 8
Source File: NetworkUtils.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"MissingPermission"})
public static int getAPNType(Context context) {
    int netType = CONNECTION_TYPE_NULL;
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    if (networkInfo == null) {
        return CONNECTION_TYPE_NULL;
    }
    int nType = networkInfo.getType();
    if (nType == ConnectivityManager.TYPE_WIFI) {
        netType = CONNECTION_TYPE_WIFI;
    } else if (nType == ConnectivityManager.TYPE_MOBILE) {
        int nSubType = networkInfo.getSubtype();
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        if (nSubType == TelephonyManager.NETWORK_TYPE_LTE
                && !telephonyManager.isNetworkRoaming()) {
            netType = CONNECTION_TYPE_4G;
        } else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS
                || nSubType == TelephonyManager.NETWORK_TYPE_HSDPA
                || nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0
                && !telephonyManager.isNetworkRoaming()) {
            netType = CONNECTION_TYPE_3G;
        } else if (nSubType == TelephonyManager.NETWORK_TYPE_GPRS
                || nSubType == TelephonyManager.NETWORK_TYPE_EDGE
                || nSubType == TelephonyManager.NETWORK_TYPE_CDMA
                && !telephonyManager.isNetworkRoaming()) {
            netType = CONNECTION_TYPE_2G;
        } else {
            netType = CONNECTION_TYPE_2G;
        }
    }
    return netType;
}
 
Example 9
Source File: LocalNetHelper.java    From base-module with Apache License 2.0 4 votes vote down vote up
/**
 * 获取当前的网络类型(WIFI,2G,3G,4G)
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
 *
 * @param context 上下文
 * @return 网络类型
 * <ul>
 * <li>{@link #NETWORK_WIFI   } = 1;</li>
 * <li>{@link #NETWORK_4G     } = 4;</li>
 * <li>{@link #NETWORK_3G     } = 3;</li>
 * <li>{@link #NETWORK_2G     } = 2;</li>
 * <li>{@link #NETWORK_UNKNOWN} = 5;</li>
 * <li>{@link #NETWORK_NO     } = -1;</li>
 * </ul>
 */
public static int getNetWorkType(Context context) {
    int netType = NETWORK_NO;
    NetworkInfo info = getActiveNetworkInfo(context);
    if (info != null && info.isAvailable()) {

        if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            netType = NETWORK_WIFI;
        } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
            switch (info.getSubtype()) {

                case NETWORK_TYPE_GSM:
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    netType = NETWORK_2G;
                    break;

                case NETWORK_TYPE_TD_SCDMA:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_UMTS:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                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:
                    netType = NETWORK_3G;
                    break;

                case NETWORK_TYPE_IWLAN:
                case TelephonyManager.NETWORK_TYPE_LTE:
                    netType = NETWORK_4G;
                    break;
                default:

                    String subtypeName = info.getSubtypeName();
                    if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                            || subtypeName.equalsIgnoreCase("WCDMA")
                            || subtypeName.equalsIgnoreCase("CDMA2000")) {
                        netType = NETWORK_3G;
                    } else {
                        netType = NETWORK_UNKNOWN;
                    }
                    break;
            }
        } else {
            netType = NETWORK_UNKNOWN;
        }
    }
    return netType;
}
 
Example 10
Source File: DownloaderService.java    From UnityOBBDownloader with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the network type based upon the type and subtype returned from
 * the connectivity manager. Subtype is only used for cellular signals.
 *
 * @param type
 * @param subType
 */
private void updateNetworkType(int type, int subType) {
    switch (type) {
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_BLUETOOTH:
            mIsCellularConnection = false;
            mIsAtLeast3G = false;
            mIsAtLeast4G = false;
            break;
        case ConnectivityManager.TYPE_WIMAX:
            mIsCellularConnection = true;
            mIsAtLeast3G = true;
            mIsAtLeast4G = true;
            break;
        case ConnectivityManager.TYPE_MOBILE:
            mIsCellularConnection = true;
            switch (subType) {
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    mIsAtLeast3G = false;
                    mIsAtLeast4G = false;
                    break;
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_UMTS:
                    mIsAtLeast3G = true;
                    mIsAtLeast4G = false;
                    break;
                case TelephonyManager.NETWORK_TYPE_LTE: // 4G
                case TelephonyManager.NETWORK_TYPE_EHRPD: // 3G ++ interop
                                                          // with 4G
                case TelephonyManager.NETWORK_TYPE_HSPAP: // 3G ++ but
                                                          // marketed as
                                                          // 4G
                    mIsAtLeast3G = true;
                    mIsAtLeast4G = true;
                    break;
                default:
                    mIsCellularConnection = false;
                    mIsAtLeast3G = false;
                    mIsAtLeast4G = false;
            }
    }
}
 
Example 11
Source File: NetworkUtils.java    From AcgClub with MIT License 4 votes vote down vote up
/**
 * Return type of network.
 * <p>Must hold
 * {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />}</p>
 *
 * @return type of network <ul> <li>{@link NetworkUtils.NetworkType#NETWORK_WIFI   } </li>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_4G     } </li> <li>{@link
 * NetworkUtils.NetworkType#NETWORK_3G     } </li> <li>{@link NetworkUtils.NetworkType#NETWORK_2G
 * } </li> <li>{@link NetworkUtils.NetworkType#NETWORK_UNKNOWN} </li> <li>{@link
 * NetworkUtils.NetworkType#NETWORK_NO     } </li> </ul>
 */
@RequiresPermission(ACCESS_NETWORK_STATE)
public static NetworkType getNetworkType() {
  NetworkType netType = NetworkType.NETWORK_NO;
  NetworkInfo info = getActiveNetworkInfo();
  if (info != null && info.isAvailable()) {

    if (info.getType() == ConnectivityManager.TYPE_WIFI) {
      netType = NetworkType.NETWORK_WIFI;
    } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
      switch (info.getSubtype()) {

        case NETWORK_TYPE_GSM:
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EDGE:
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_IDEN:
          netType = NetworkType.NETWORK_2G;
          break;

        case NETWORK_TYPE_TD_SCDMA:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_UMTS:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        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:
          netType = NetworkType.NETWORK_3G;
          break;

        case NETWORK_TYPE_IWLAN:
        case TelephonyManager.NETWORK_TYPE_LTE:
          netType = NetworkType.NETWORK_4G;
          break;
        default:

          String subtypeName = info.getSubtypeName();
          if (subtypeName.equalsIgnoreCase("TD-SCDMA")
              || subtypeName.equalsIgnoreCase("WCDMA")
              || subtypeName.equalsIgnoreCase("CDMA2000")) {
            netType = NetworkType.NETWORK_3G;
          } else {
            netType = NetworkType.NETWORK_UNKNOWN;
          }
          break;
      }
    } else {
      netType = NetworkType.NETWORK_UNKNOWN;
    }
  }
  return netType;
}
 
Example 12
Source File: CommonUtils.java    From BigApp_WordPress_Android with Apache License 2.0 4 votes vote down vote up
public static boolean isFastMobileNetwork(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    // System.out.println("request_http netType networkType = "
    // + telephonyManager.getNetworkType());
    switch (telephonyManager.getNetworkType()) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
            return false; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_CDMA:
            return false; // ~ 14-64 kbps
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return false; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
            return true; // ~ 400-1000 kbps
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
            return true; // ~ 600-1400 kbps
        case TelephonyManager.NETWORK_TYPE_GPRS:
            return false; // ~ 100 kbps
        case TelephonyManager.NETWORK_TYPE_HSDPA:
            return true; // ~ 2-14 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPA:
            return true; // ~ 700-1700 kbps
        case TelephonyManager.NETWORK_TYPE_HSUPA:
            return true; // ~ 1-23 Mbps
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return true; // ~ 400-7000 kbps
        case TelephonyManager.NETWORK_TYPE_EHRPD:
            return true; // ~ 1-2 Mbps
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            return true; // ~ 5 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            return true; // ~ 10-20 Mbps
        case TelephonyManager.NETWORK_TYPE_IDEN:
            return false; // ~25 kbps
        case TelephonyManager.NETWORK_TYPE_LTE:
            return true; // ~ 10+ Mbps
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            return false;
        default:
            return false;
    }
}
 
Example 13
Source File: Connectivity.java    From FaceSlim with GNU General Public License v2.0 4 votes vote down vote up
/**
  * Check if the connection is fast
  * @param type int
  * @param subType int
  * @return boolean
  */
 public static boolean isConnectionFast(int type, int subType) {
     if (type == ConnectivityManager.TYPE_WIFI) {
         return true;
     } else if (type == ConnectivityManager.TYPE_MOBILE) {
         switch(subType) {
             case TelephonyManager.NETWORK_TYPE_1xRTT:
                 return false; // ~ 50-100 kbps
             case TelephonyManager.NETWORK_TYPE_CDMA:
                 return false; // ~ 14-64 kbps
             case TelephonyManager.NETWORK_TYPE_EDGE:
                 return false; // ~ 50-100 kbps
             case TelephonyManager.NETWORK_TYPE_EVDO_0:
                 return true; // ~ 400-1000 kbps
             case TelephonyManager.NETWORK_TYPE_EVDO_A:
                 return true; // ~ 600-1400 kbps
             case TelephonyManager.NETWORK_TYPE_GPRS:
                 return false; // ~ 100 kbps
             case TelephonyManager.NETWORK_TYPE_HSDPA:
                 return true; // ~ 2-14 Mbps
             case TelephonyManager.NETWORK_TYPE_HSPA:
                 return true; // ~ 700-1700 kbps
             case TelephonyManager.NETWORK_TYPE_HSUPA:
                 return true; // ~ 1-23 Mbps
             case TelephonyManager.NETWORK_TYPE_UMTS:
                 return true; // ~ 400-7000 kbps
/*
 * Above API level 7, make sure to set android:targetSdkVersion
 * to appropriate level to use these
 */
             case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11
                 return true; // ~ 1-2 Mbps
             case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
                 return true; // ~ 5 Mbps
             case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
                 return true; // ~ 10-20 Mbps
             case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
                 return false; // ~25 kbps
             case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
                 return true; // ~ 10+ Mbps
             // Unknown
             case TelephonyManager.NETWORK_TYPE_UNKNOWN:
             default:
                 return false;
         }
     } else {
         return false;
     }
 }
 
Example 14
Source File: DownloaderService.java    From Alite with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Updates the network type based upon the type and subtype returned from
 * the connectivity manager. Subtype is only used for cellular signals.
 * 
 * @param type
 * @param subType
 */
private void updateNetworkType(int type, int subType) {
    switch (type) {
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_BLUETOOTH:
            mIsCellularConnection = false;
            mIsAtLeast3G = false;
            break;
        case ConnectivityManager.TYPE_WIMAX:
            mIsCellularConnection = true;
            mIsAtLeast3G = true;
            break;
        case ConnectivityManager.TYPE_MOBILE:
            mIsCellularConnection = true;
            switch (subType) {
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    mIsAtLeast3G = false;
                    break;
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_UMTS:
                    mIsAtLeast3G = true;
                    break;
                case TelephonyManager.NETWORK_TYPE_LTE: // 4G
                case TelephonyManager.NETWORK_TYPE_EHRPD: // 3G ++ interop
                                                          // with 4G
                case TelephonyManager.NETWORK_TYPE_HSPAP: // 3G ++ but
                                                          // marketed as
                                                          // 4G
                    mIsAtLeast3G = true;
                    break;
                default:
                    mIsCellularConnection = false;
                    mIsAtLeast3G = false;
            }
    }
}
 
Example 15
Source File: ConnectivityUtil.java    From MVPAndroidBootstrap with Apache License 2.0 4 votes vote down vote up
/**
 * Check if the connection is fast
 *
 * @param type
 * @param subType
 * @return
 */
public static boolean isConnectionFast(int type, int subType) {
    if (type == ConnectivityManager.TYPE_WIFI) {
        return true;
    } else if (type == ConnectivityManager.TYPE_MOBILE) {
        switch (subType) {
            case TelephonyManager.NETWORK_TYPE_1xRTT:
                return false; // ~ 50-100 kbps
            case TelephonyManager.NETWORK_TYPE_CDMA:
                return false; // ~ 14-64 kbps
            case TelephonyManager.NETWORK_TYPE_EDGE:
                return false; // ~ 50-100 kbps
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
                return true; // ~ 400-1000 kbps
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
                return true; // ~ 600-1400 kbps
            case TelephonyManager.NETWORK_TYPE_GPRS:
                return false; // ~ 100 kbps
            case TelephonyManager.NETWORK_TYPE_HSDPA:
                return true; // ~ 2-14 Mbps
            case TelephonyManager.NETWORK_TYPE_HSPA:
                return true; // ~ 700-1700 kbps
            case TelephonyManager.NETWORK_TYPE_HSUPA:
                return true; // ~ 1-23 Mbps
            case TelephonyManager.NETWORK_TYPE_UMTS:
                return true; // ~ 400-7000 kbps
        /*
         * Above API level 7, make sure to set android:targetSdkVersion
* to appropriate level to use these
*/
            case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11
                return true; // ~ 1-2 Mbps
            case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
                return true; // ~ 5 Mbps
            case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
                return true; // ~ 10-20 Mbps
            case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
                return false; // ~25 kbps
            case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
                return true; // ~ 10+ Mbps
            // Unknown
            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            default:
                return false;
        }
    } else {
        return false;
    }
}
 
Example 16
Source File: HomeActivity.java    From apollo-DuerOS with Apache License 2.0 4 votes vote down vote up
private void updateNetworkStatus() {
    NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
    if (info != null) {
        LogUtil.i(TAG, "network type name: " + info.getTypeName());
        LogUtil.i(TAG, "network subType name: " + info.getSubtypeName());
        if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            if (mWifiManager.getConnectionInfo() != null) {
                int rssi = mWifiManager.getConnectionInfo().getRssi();
                int level = WifiManager.calculateSignalLevel(rssi, 4);
                switch (level) {
                    case 0:
                        mNetworkImg.setImageResource(R.drawable.ic_wifi4);
                        break;
                    case 1:
                        mNetworkImg.setImageResource(R.drawable.ic_wifi3);
                        break;
                    case 2:
                        mNetworkImg.setImageResource(R.drawable.ic_wifi2);
                        break;
                    case 3:
                        mNetworkImg.setImageResource(R.drawable.ic_wifi);
                        break;
                    default:
                        break;
                }
                LogUtil.i(TAG, "Wifi Level " + level);
            }
        } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
            switch (info.getSubtype()) {
                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:
                    mNetworkImg.setImageResource(R.drawable.ic_net_e);
                    break;
                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:
                    mNetworkImg.setImageResource(R.drawable.ic_net_3g);
                    break;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    mNetworkImg.setImageResource(R.drawable.ic_net_4g);
                    break;
                default:
                    mNetworkImg.setImageResource(R.drawable.ic_net_none);
                    break;
            }
        }
    } else {
        mNetworkImg.setImageResource(R.drawable.ic_net_none);
    }
}
 
Example 17
Source File: NetCompat.java    From Common with Apache License 2.0 4 votes vote down vote up
/**
 * Get the current network type
 *
 * @return type 0: NO_AVAILABLE, 1: UN_CONNECTED, 2: CONNECTED_MOBILE, 3: CONNECTED_WIFI
 */
private static int getNetworkType(Context context) {
    ConnectivityManager connectMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectMgr.getActiveNetworkInfo();
    if (networkInfo == null) {
        /** No network */
        return NetState.NO_AVAILABLE;
    }
    if (!networkInfo.isConnected()) {
        /** The network is disconnected or closed */
        return NetState.UN_CONNECTED;
    }
    if (networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
        /** Ethernet network */
        return NetState.CONNECTED_MOBILE;
    } else if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        /** WiFi network, when activated, all data traffic will use this connection by default */
        return NetState.CONNECTED_WIFI;
    } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        /** Mobile data connection, cannot coexist with connection, if wifi is turned on, it is automatically closed */
        switch (networkInfo.getSubtype()) {
            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:
                /** 2G network */
                NetSubState.NET_SUB_STATUS = NetSubState.NETWORK_TYPE_2G;
                return NetState.CONNECTED_MOBILE;

            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:
                /** 3G network */
                NetSubState.NET_SUB_STATUS = NetSubState.NETWORK_TYPE_3G;
                return NetState.CONNECTED_MOBILE;

            case TelephonyManager.NETWORK_TYPE_LTE:
                /** 4G network */
                NetSubState.NET_SUB_STATUS = NetSubState.NETWORK_TYPE_4G;
                return NetState.CONNECTED_MOBILE;

            default:
                /** Default 4G network */
                NetSubState.NET_SUB_STATUS = NetSubState.NETWORK_TYPE_4G;
                return NetState.CONNECTED_MOBILE;
        }
    }
    /** Unknown network */
    return NetState.NO_AVAILABLE;
}
 
Example 18
Source File: NetworkUtils.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
/**
 * Return type of network.
 * <p>Must hold {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />}</p>
 *
 * @return type of network
 * <ul>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_ETHERNET} </li>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_WIFI    } </li>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_4G      } </li>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_3G      } </li>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_2G      } </li>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_UNKNOWN } </li>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_NO      } </li>
 * </ul>
 */
@RequiresPermission(ACCESS_NETWORK_STATE)
public static NetworkType getNetworkType() {
    if (isEthernet()) {
        return NetworkType.NETWORK_ETHERNET;
    }
    NetworkInfo info = getActiveNetworkInfo();
    if (info != null && info.isAvailable()) {
        if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            return NetworkType.NETWORK_WIFI;
        } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
            switch (info.getSubtype()) {
                case TelephonyManager.NETWORK_TYPE_GSM:
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    return NetworkType.NETWORK_2G;

                case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_UMTS:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                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 NetworkType.NETWORK_3G;

                case TelephonyManager.NETWORK_TYPE_IWLAN:
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return NetworkType.NETWORK_4G;

                case TelephonyManager.NETWORK_TYPE_NR:
                    return NetworkType.NETWORK_5G;
                default:
                    String subtypeName = info.getSubtypeName();
                    if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                            || subtypeName.equalsIgnoreCase("WCDMA")
                            || subtypeName.equalsIgnoreCase("CDMA2000")) {
                        return NetworkType.NETWORK_3G;
                    } else {
                        return NetworkType.NETWORK_UNKNOWN;
                    }
            }
        } else {
            return NetworkType.NETWORK_UNKNOWN;
        }
    }
    return NetworkType.NETWORK_NO;
}
 
Example 19
Source File: Util.java    From NMSAlphabetAndroidApp with MIT License 4 votes vote down vote up
private static boolean isConnectionFast(int type, int subType){
    if(type == ConnectivityManager.TYPE_WIFI){
        return true;
    } else if (type == ConnectivityManager.TYPE_MOBILE){
        switch (subType){
            case TelephonyManager.NETWORK_TYPE_1xRTT:
                return false; // ~ 50-100 kbps
            case TelephonyManager.NETWORK_TYPE_CDMA:
                return false; // ~ 14-64 kbps
            case TelephonyManager.NETWORK_TYPE_EDGE:
                return false; // ~ 50-100 kbps
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
                return true; // ~ 400-1000 kbps
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
                return true; // ~ 600-1400 kbps
            case TelephonyManager.NETWORK_TYPE_GPRS:
                return false; // ~ 100 kbps
            case TelephonyManager.NETWORK_TYPE_HSDPA:
                return true; // ~ 2-14 Mbps
            case TelephonyManager.NETWORK_TYPE_HSPA:
                return true; // ~ 700-1700 kbps
            case TelephonyManager.NETWORK_TYPE_HSUPA:
                return true; // ~ 1-23 Mbps
            case TelephonyManager.NETWORK_TYPE_UMTS:
                return true; // ~ 400-7000 kbps
            case TelephonyManager.NETWORK_TYPE_EHRPD:
                return true; // ~ 1-2 Mbps
            case TelephonyManager.NETWORK_TYPE_EVDO_B:
                return true; // ~ 5 Mbps
            case TelephonyManager.NETWORK_TYPE_HSPAP:
                return true; // ~ 10-20 Mbps
            case TelephonyManager.NETWORK_TYPE_IDEN:
                return false; // ~25 kbps
            case TelephonyManager.NETWORK_TYPE_LTE:
                return true; // ~ 10+ Mbps
            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            default:
                return false;
        }
    } else {
        return false;
    }
}
 
Example 20
Source File: Network.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Check if the connection is fast
 *
 * @param type    of connection
 * @param subType of connection
 * @return true if the connection is 3g or above
 */
public static boolean isConnectionFast(final int type, final int subType) {

    switch (type) {

        case ConnectivityManager.TYPE_WIFI:
            return true;

        case ConnectivityManager.TYPE_WIMAX:
            return true;

        case ConnectivityManager.TYPE_MOBILE:

            switch (subType) {

                case TelephonyManager.NETWORK_TYPE_1xRTT:
                    return false; // ~ 50-100 kbps
                case TelephonyManager.NETWORK_TYPE_CDMA:
                    return false; // ~ 14-64 kbps
                case TelephonyManager.NETWORK_TYPE_EDGE:
                    return false; // ~ 50-100 kbps
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                    return true; // ~ 400-1000 kbps
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                    return true; // ~ 600-1400 kbps
                case TelephonyManager.NETWORK_TYPE_GPRS:
                    return false; // ~ 100 kbps
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                    return true; // ~ 2-14 Mbps
                case TelephonyManager.NETWORK_TYPE_HSPA:
                    return true; // ~ 700-1700 kbps
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                    return true; // ~ 1-23 Mbps
                case TelephonyManager.NETWORK_TYPE_UMTS:
                    return true; // ~ 400-7000 kbps
                case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11
                    return true; // ~ 1-2 Mbps
                case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
                    return true; // ~ 5 Mbps
                case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
                    return true; // ~ 10-20 Mbps
                case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
                    return false; // ~25 kbps
                case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
                    return true; // ~ 10+ Mbps
                // Unknown
                case TelephonyManager.NETWORK_TYPE_UNKNOWN:

                default:
                    return false;
            }

        default:
            return false;

    }
}