Java Code Examples for android.net.ConnectivityManager#TYPE_ETHERNET

The following examples show how to use android.net.ConnectivityManager#TYPE_ETHERNET . 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: NetworkInfoBroadcastReceiver.java    From android-sdk with MIT License 6 votes vote down vote up
/**
 * maps the network states to lan, wifi or the broadband types (edge, hsdpa...)
 *
 * @return the mapped network type name or "unknown"
 */
public static String getNetworkInfoString() {
    if (latestNetworkInfo == null) {
        return "unknown";
    }
    switch (latestNetworkInfo.getType()) {
        case ConnectivityManager.TYPE_ETHERNET:
            return "lan";
        case ConnectivityManager.TYPE_MOBILE:
            return latestNetworkInfo.getSubtypeName().toLowerCase();
        case ConnectivityManager.TYPE_WIFI:
            return "wifi";
        default:
            return "unknown";
    }
}
 
Example 2
Source File: FTPServerFragment.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = conMan.getActiveNetworkInfo();
        if ((netInfo != null && (netInfo.getType() == ConnectivityManager.TYPE_WIFI || netInfo.getType() == ConnectivityManager.TYPE_ETHERNET))
|| FTPService.isEnabledWifiHotspot(getContext())) {
            // connected to wifi or eth
            ftpBtn.setEnabled(true);
        } else {
            // wifi or eth connection lost
            stopServer();
            statusText.setText(spannedStatusNoConnection);
            ftpBtn.setEnabled(true);
            ftpBtn.setEnabled(false);
            ftpBtn.setText(getResources().getString(R.string.start_ftp).toUpperCase());
        }
    }
 
Example 3
Source File: FTPService.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
public static boolean isConnectedToLocalNetwork(Context context) {
    boolean connected = false;
    ConnectivityManager cm = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    connected = ni != null
            && ni.isConnected()
            && (ni.getType() & (ConnectivityManager.TYPE_WIFI | ConnectivityManager.TYPE_ETHERNET)) != 0;
    if (!connected) {
        Log.d(TAG, "isConnectedToLocalNetwork: see if it is an USB AP");
        try {
            for (NetworkInterface netInterface : Collections.list(NetworkInterface
                    .getNetworkInterfaces())) {
                if (netInterface.getDisplayName().startsWith("rndis")) {
                    connected = true;
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }
    return connected;
}
 
Example 4
Source File: NetworkStateReceiver.java    From ForPDA with GNU General Public License v3.0 6 votes vote down vote up
public NetworkInfo.State getCurrentConnectionType() {
    if (!managerDelegate.activeNetworkExists() ||
            !managerDelegate.isConnected()) {
        return NetworkInfo.State.DISCONNECTED;
    }

    switch (managerDelegate.getNetworkType()) {
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_WIMAX:
        case ConnectivityManager.TYPE_MOBILE:
            return NetworkInfo.State.CONNECTED;
        default:
            return NetworkInfo.State.UNKNOWN;
    }
}
 
Example 5
Source File: MainActivity.java    From goproxy-android with GNU General Public License v3.0 6 votes vote down vote up
public static String getIpAddress(Context context) {
    NetworkInfo info = ((ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
    if (info != null && info.isConnected()) {
        // 3/4g网络
        if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
            try {
                for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
                    NetworkInterface intf = en.nextElement();
                    for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                        InetAddress inetAddress = enumIpAddr.nextElement();
                        if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
                            return inetAddress.getHostAddress();
                        }
                    }
                }
            } catch (SocketException e) {
                e.printStackTrace();
            }

        } else if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            //  wifi网络
            WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            String ipAddress = intIP2StringIP(wifiInfo.getIpAddress());
            return ipAddress;
        } else if (info.getType() == ConnectivityManager.TYPE_ETHERNET) {
            // 有限网络
            return getLocalIp();
        }
    }
    return null;
}
 
Example 6
Source File: ApplicationLoader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isConnectedToWiFi() {
    try {
        ensureCurrentNetworkGet(false);
        if (currentNetworkInfo != null && (currentNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI || currentNetworkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) && currentNetworkInfo.getState() == NetworkInfo.State.CONNECTED) {
            return true;
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    return false;
}
 
Example 7
Source File: Requirements.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isActiveNetworkMetered(
    ConnectivityManager connectivityManager, NetworkInfo networkInfo) {
  if (Util.SDK_INT >= 16) {
    return connectivityManager.isActiveNetworkMetered();
  }
  int type = networkInfo.getType();
  return type != ConnectivityManager.TYPE_WIFI
      && type != ConnectivityManager.TYPE_BLUETOOTH
      && type != ConnectivityManager.TYPE_ETHERNET;
}
 
Example 8
Source File: JoH.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isLANConnected() {
    final ConnectivityManager cm =
            (ConnectivityManager) xdrip.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    final boolean isConnected = activeNetwork != null &&
            activeNetwork.isConnected();
    return isConnected && ((activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
            || (activeNetwork.getType() == ConnectivityManager.TYPE_ETHERNET)
            || (activeNetwork.getType() == ConnectivityManager.TYPE_BLUETOOTH));
}
 
Example 9
Source File: ApplicationLoader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isConnectedOrConnectingToWiFi() {
    try {
        ensureCurrentNetworkGet(false);
        if (currentNetworkInfo != null && (currentNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI || currentNetworkInfo.getType() == ConnectivityManager.TYPE_ETHERNET)) {
            NetworkInfo.State state = currentNetworkInfo.getState();
            if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING || state == NetworkInfo.State.SUSPENDED) {
                return true;
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    return false;
}
 
Example 10
Source File: Util.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the {@link C.NetworkType} of the current network connection. {@link
 * C#NETWORK_TYPE_UNKNOWN} will be returned if the {@code ACCESS_NETWORK_STATE} permission is not
 * granted or the network connection type couldn't be determined.
 *
 * @param context A context to access the connectivity manager.
 * @return The {@link C.NetworkType} of the current network connection, or {@link
 *     C#NETWORK_TYPE_UNKNOWN} if the {@code ACCESS_NETWORK_STATE} permission is not granted or
 *     {@code context} is null.
 */
public static @C.NetworkType int getNetworkType(@Nullable Context context) {
  if (context == null) {
    return C.NETWORK_TYPE_UNKNOWN;
  }
  NetworkInfo networkInfo;
  try {
    ConnectivityManager connectivityManager =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager == null) {
      return C.NETWORK_TYPE_UNKNOWN;
    }
    networkInfo = connectivityManager.getActiveNetworkInfo();
  } catch (SecurityException e) {
    // Permission ACCESS_NETWORK_STATE not granted.
    return C.NETWORK_TYPE_UNKNOWN;
  }
  if (networkInfo == null || !networkInfo.isConnected()) {
    return C.NETWORK_TYPE_OFFLINE;
  }
  switch (networkInfo.getType()) {
    case ConnectivityManager.TYPE_WIFI:
      return C.NETWORK_TYPE_WIFI;
    case ConnectivityManager.TYPE_WIMAX:
      return C.NETWORK_TYPE_4G;
    case ConnectivityManager.TYPE_MOBILE:
    case ConnectivityManager.TYPE_MOBILE_DUN:
    case ConnectivityManager.TYPE_MOBILE_HIPRI:
      return getMobileNetworkType(networkInfo);
    case ConnectivityManager.TYPE_ETHERNET:
      return C.NETWORK_TYPE_ETHERNET;
    default: // Ethernet, VPN, Bluetooth, Dummy.
      return C.NETWORK_TYPE_OTHER;
  }
}
 
Example 11
Source File: HueDeviceProfile.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * LocalNetwork接続設定の状態を取得します.
 * @return trueの場合は有効、それ以外の場合は無効
 */
private boolean isLocalNetworkEnabled() {
    ConnectivityManager convManager = (ConnectivityManager) getContext().getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = convManager.getActiveNetworkInfo();
    boolean isEthernet = false;
    if (info != null) {
        return (info.getType() == ConnectivityManager.TYPE_ETHERNET
                || info.getType() == ConnectivityManager.TYPE_WIFI);
    } else {
        return false;
    }
}
 
Example 12
Source File: DeviceStatusUtil.java    From under-the-hood with Apache License 2.0 5 votes vote down vote up
/**
 * The current network (ie. internet) connectivity state. Needs correct permission to work.
 *
 * @param context
 * @return state
 */
//@RequiresPermission(Manifest.permission.ACCESS_NETWORK_STATE)
public static ConnectionState getNetworkConnectivityState(@NonNull Context context) {
    if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_NETWORK_STATE) == PackageManager.PERMISSION_GRANTED) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();

        if (activeNetwork != null) {
            if (activeNetwork.isConnectedOrConnecting()) {
                if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
                    return ConnectionState.CONNECTED_WIFI;
                }
                if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE || activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE_DUN) {
                    return ConnectionState.CONNECTED_MOBILE;
                }
                if (activeNetwork.getType() == ConnectivityManager.TYPE_ETHERNET) {
                    return ConnectionState.CONNECTED_ETHERNET;
                }
                if (activeNetwork.getType() == ConnectivityManager.TYPE_BLUETOOTH) {
                    return ConnectionState.CONNECTED_BT;
                }
                if (activeNetwork.getType() == ConnectivityManager.TYPE_VPN) {
                    return ConnectionState.CONNECTED_BT;
                }
                return ConnectionState.CONNECTED_OTHER;
            }
        }

        return ConnectionState.DISCONNECTED;
    }
    return ConnectionState.PERMISSION_NEEDED;
}
 
Example 13
Source File: NetWorkUtils.java    From Simpler with Apache License 2.0 5 votes vote down vote up
/**
 * 判断当前网络的类型是否是ETHERNET
 *
 * @param context 上下文
 * @return 当前网络的类型是否是ETHERNET。false:当前没有网络连接或者网络类型不是ETHERNET
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public static boolean isEthernetByType(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        return false;
    }
    else {
        return getCurrentNetworkType(context) ==
                ConnectivityManager.TYPE_ETHERNET;
    }
}
 
Example 14
Source File: JoH.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isMobileDataOrEthernetConnected() {
    final ConnectivityManager cm =
            (ConnectivityManager) xdrip.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    final boolean isConnected = activeNetwork != null &&
            activeNetwork.isConnected();
    return isConnected && ((activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) || (activeNetwork.getType() == ConnectivityManager.TYPE_ETHERNET));
}
 
Example 15
Source File: NetworkManager.java    From Intra with Apache License 2.0 4 votes vote down vote up
/**
 * Post-Lollipop, we can use VpnService.Builder.addDisallowedApplication to exclude Intra from its
 * own VPN.  If for some reason we needed to get the IP address of the non-VPN resolvers, we could
 * use ConnectivityManager.getActiveNetwork().getLinkProperties().getDnsServers().
 *
 * Pre-Lollipop, there is no official way to get the non-VPN DNS servers, but we need them in
 * order to do DNS lookups on protected sockets in Go, in order to resolve DNS server names when
 * the current server connection is broken, without disabling the VPN.  This implementation
 * exposes the hidden version of LinkProperties that was present prior to Lollipop, in order to
 * extract the DNS server IPs.
 *
 * @return The (unencrypted) DNS servers used by the underlying networks.
 */
List<InetAddress> getSystemResolvers() {
  // This list of network types is in roughly descending priority order, so that the first
  // entries in the returned list are most likely to be the appropriate resolvers.
  int[] networkTypes = new int[]{
      ConnectivityManager.TYPE_ETHERNET,
      ConnectivityManager.TYPE_WIFI,
      ConnectivityManager.TYPE_MOBILE,
      ConnectivityManager.TYPE_WIMAX,
  };

  List<InetAddress> resolvers = new ArrayList<>();
  if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
    LogWrapper.log(Log.ASSERT, LOG_TAG, "This function should never be called in L+.");
    return resolvers;
  }

  try {
    // LinkProperties ConnectivityManager.getLinkProperties(int type) (removed in Lollipop)
    Method getLinkProperties = ConnectivityManager.class
        .getMethod("getLinkProperties", int.class);
    // LinkProperties, which existed before Lollipop but had a different API and was not exposed.
    Class<?> linkPropertiesClass = Class.forName("android.net.LinkProperties");
    // Collection<InetAddress> LinkProperties.getDnses() (replaced by getDnsServers in Lollipop).
    Method getDnses = linkPropertiesClass.getMethod("getDnses");

    for (int networkType : networkTypes) {
      Object linkProperties = getLinkProperties.invoke(connectivityManager, networkType);
      if (linkProperties == null) {
        // No network of this type.
        continue;
      }
      Collection<?> addresses = (Collection<?>) getDnses.invoke(linkProperties);
      for (Object address : addresses) {
        resolvers.add((InetAddress)address);
      }
    }
  } catch (Exception e) {
    LogWrapper.logException(e);
  }

  return resolvers;
}
 
Example 16
Source File: PlayerUtils.java    From DKVideoPlayer with Apache License 2.0 4 votes vote down vote up
/**
 * 判断当前网络类型
 */
public static int getNetworkType(Context context) {
    //改为context.getApplicationContext(),防止在Android 6.0上发生内存泄漏
    ConnectivityManager connectMgr = (ConnectivityManager) context.getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    if (connectMgr == null) {
        return NO_NETWORK;
    }

    NetworkInfo networkInfo = connectMgr.getActiveNetworkInfo();
    if (networkInfo == null) {
        // 没有任何网络
        return NO_NETWORK;
    }
    if (!networkInfo.isConnected()) {
        // 网络断开或关闭
        return NETWORK_CLOSED;
    }
    if (networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
        // 以太网网络
        return NETWORK_ETHERNET;
    } else if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        // wifi网络,当激活时,默认情况下,所有的数据流量将使用此连接
        return NETWORK_WIFI;
    } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        // 移动数据连接,不能与连接共存,如果wifi打开,则自动关闭
        switch (networkInfo.getSubtype()) {
            // 2G
            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:
                // 3G
            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:
                // 4G
            case TelephonyManager.NETWORK_TYPE_LTE:
                // 5G
            case TelephonyManager.NETWORK_TYPE_NR:
                return NETWORK_MOBILE;
        }
    }
    // 未知网络
    return NETWORK_UNKNOWN;
}
 
Example 17
Source File: Network.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Get the current connection type from the {@link ConnectivityManager}
 *
 * @param ctx the application Context
 * @return the integer constant of the connection type
 */
public static int getConnectionType(final Context ctx) {
    final NetworkInfo info = getActiveNetworkInfo(ctx);
    final int infoType = info.getType();

    switch (infoType) {

        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_BLUETOOTH:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "getConnectionType: CONNECTION_TYPE_WIFI");
            }
            return CONNECTION_TYPE_WIFI;

        case ConnectivityManager.TYPE_WIMAX:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "getConnectionType: CONNECTION_TYPE_4G");
            }
            return CONNECTION_TYPE_4G;

        case ConnectivityManager.TYPE_MOBILE:

            final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
            final int networkType = tm.getNetworkType();

            switch (networkType) {

                case TelephonyManager.NETWORK_TYPE_GPRS: // ~ 100 kbps
                case TelephonyManager.NETWORK_TYPE_EDGE: // ~ 50-100 kbps
                case TelephonyManager.NETWORK_TYPE_CDMA: // ~ 14-64 kbps
                case TelephonyManager.NETWORK_TYPE_1xRTT: // ~ 50-100 kbps
                case TelephonyManager.NETWORK_TYPE_IDEN: // ~25 kbps
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "getConnectionType: CONNECTION_TYPE_2G");
                    }
                    return CONNECTION_TYPE_2G;

                case TelephonyManager.NETWORK_TYPE_UMTS: // ~ 400-7000 kbps
                case TelephonyManager.NETWORK_TYPE_EVDO_0: // ~ 400-1000 kbps
                case TelephonyManager.NETWORK_TYPE_EVDO_A: // ~ 600-1400 kbps
                case TelephonyManager.NETWORK_TYPE_HSDPA: // ~ 2-14 Mbps
                case TelephonyManager.NETWORK_TYPE_HSUPA: // ~ 1-23 Mbps
                case TelephonyManager.NETWORK_TYPE_HSPA: // ~ 700-1700 kbps
                case TelephonyManager.NETWORK_TYPE_EVDO_B: // ~ 5 Mbps
                case TelephonyManager.NETWORK_TYPE_EHRPD: // ~ 1-2 Mbps
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "getConnectionType: CONNECTION_TYPE_3G");
                    }
                    return CONNECTION_TYPE_3G;

                case TelephonyManager.NETWORK_TYPE_LTE: // ~ 10+ Mbps
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "getConnectionType: CONNECTION_TYPE_4G");
                    }
                    return CONNECTION_TYPE_4G;
                case TelephonyManager.NETWORK_TYPE_HSPAP: // ~ 10-20 Mbps
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "getConnectionType: CONNECTION_TYPE_4G");
                    }
                    return CONNECTION_TYPE_4G;

                default:
                    if (DEBUG) {
                        MyLog.w(CLS_NAME, "getConnectionType: CONNECTION_TYPE_UNKNOWN");
                    }
                    return CONNECTION_TYPE_UNKNOWN;

            }

        default:
            if (DEBUG) {
                MyLog.w(CLS_NAME, "getConnectionType: CONNECTION_TYPE_UNKNOWN");
            }
            return CONNECTION_TYPE_UNKNOWN;
    }
}
 
Example 18
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
protected void updateNetworkType() {
	ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
	NetworkInfo info = cm.getActiveNetworkInfo();
	lastNetInfo = info;
	int type = VoIPController.NET_TYPE_UNKNOWN;
	if (info != null) {
		switch (info.getType()) {
			case ConnectivityManager.TYPE_MOBILE:
				switch (info.getSubtype()) {
					case TelephonyManager.NETWORK_TYPE_GPRS:
						type = VoIPController.NET_TYPE_GPRS;
						break;
					case TelephonyManager.NETWORK_TYPE_EDGE:
					case TelephonyManager.NETWORK_TYPE_1xRTT:
						type = VoIPController.NET_TYPE_EDGE;
						break;
					case TelephonyManager.NETWORK_TYPE_UMTS:
					case TelephonyManager.NETWORK_TYPE_EVDO_0:
						type = VoIPController.NET_TYPE_3G;
						break;
					case TelephonyManager.NETWORK_TYPE_HSDPA:
					case TelephonyManager.NETWORK_TYPE_HSPA:
					case TelephonyManager.NETWORK_TYPE_HSPAP:
					case TelephonyManager.NETWORK_TYPE_HSUPA:
					case TelephonyManager.NETWORK_TYPE_EVDO_A:
					case TelephonyManager.NETWORK_TYPE_EVDO_B:
						type = VoIPController.NET_TYPE_HSPA;
						break;
					case TelephonyManager.NETWORK_TYPE_LTE:
						type = VoIPController.NET_TYPE_LTE;
						break;
					default:
						type = VoIPController.NET_TYPE_OTHER_MOBILE;
						break;
				}
				break;
			case ConnectivityManager.TYPE_WIFI:
				type = VoIPController.NET_TYPE_WIFI;
				break;
			case ConnectivityManager.TYPE_ETHERNET:
				type = VoIPController.NET_TYPE_ETHERNET;
				break;
		}
	}
	if (controller != null) {
		controller.setNetworkType(type);
	}
}
 
Example 19
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 20
Source File: DownloaderService.java    From play-apk-expansion 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;
            }
    }
}