Java Code Examples for android.net.ConnectivityManager#TYPE_BLUETOOTH

The following examples show how to use android.net.ConnectivityManager#TYPE_BLUETOOTH . 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: DeviceConditions.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/** Returns the NCN network type corresponding to the connectivity manager network type */
private static int convertAndroidNetworkTypeToConnectionType(
        int connectivityManagerNetworkType) {
    if (connectivityManagerNetworkType == ConnectivityManager.TYPE_WIFI) {
        return ConnectionType.CONNECTION_WIFI;
    }
    // for mobile, we don't know if it is 2G, 3G, or 4G, default to worst case of 2G.
    if (connectivityManagerNetworkType == ConnectivityManager.TYPE_MOBILE) {
        return ConnectionType.CONNECTION_2G;
    }
    if (connectivityManagerNetworkType == ConnectivityManager.TYPE_BLUETOOTH) {
        return ConnectionType.CONNECTION_BLUETOOTH;
    }
    // Since NetworkConnectivityManager doesn't understand the other types, call them UNKNOWN.
    return ConnectionType.CONNECTION_UNKNOWN;
}
 
Example 2
Source File: NetworkUtil.java    From Slide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Uses the provided context to determine the current connectivity status.
 *
 * @param context A context used to retrieve connection information from
 * @return A non-null value defined in {@link Status}
 */
public static Status getConnectivityStatus(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    switch (activeNetwork != null ? activeNetwork.getType() : CONST_NO_NETWORK) {
        case ConnectivityManager.TYPE_WIFI: case ConnectivityManager.TYPE_ETHERNET:
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
                if (cm.isActiveNetworkMetered())
                    return Status.MOBILE; // respect metered wifi networks as mobile
            return Status.WIFI;
        case ConnectivityManager.TYPE_MOBILE: case ConnectivityManager.TYPE_BLUETOOTH: case ConnectivityManager.TYPE_WIMAX:
            return Status.MOBILE;
        default:
            return Status.NONE;
    }
}
 
Example 3
Source File: NetworkInfoBroadcastReceiver.java    From android-sdk with MIT License 6 votes vote down vote up
private static String typeToString(int type) {
    switch (type) {
        case ConnectivityManager.TYPE_ETHERNET:
            return "TYPE_ETHERNET";
        case ConnectivityManager.TYPE_BLUETOOTH:
            return "TYPE_BLUETOOTH";
        case ConnectivityManager.TYPE_MOBILE:
            return "TYPE_MOBILE";
        case ConnectivityManager.TYPE_MOBILE_DUN:
            return "TYPE_MOBILE_DUN";
        case ConnectivityManager.TYPE_MOBILE_HIPRI:
            return "TYPE_MOBILE_HIPRI";
        case ConnectivityManager.TYPE_MOBILE_MMS:
            return "TYPE_MOBILE_MMS";
        case ConnectivityManager.TYPE_MOBILE_SUPL:
            return "TYPE_MOBILE_SUPL";
        case ConnectivityManager.TYPE_VPN:
            return "TYPE_VPN";
        case ConnectivityManager.TYPE_WIFI:
            return "TYPE_WIFI";
        case ConnectivityManager.TYPE_WIMAX:
            return "TYPE_WIMAX";
        default:
            return "unknown";
    }
}
 
Example 4
Source File: AndroidPlatformSupport.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public boolean connectedToUnmeteredNetwork() {
	//Returns true if using unmetered connection, use shortcut method if available
	ConnectivityManager cm = (ConnectivityManager) AndroidGame.instance.getSystemService(Context.CONNECTIVITY_SERVICE);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
		return !cm.isActiveNetworkMetered();
	} else {
		NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
		return activeNetwork != null && activeNetwork.isConnectedOrConnecting() &&
				(activeNetwork.getType() == ConnectivityManager.TYPE_WIFI
				|| activeNetwork.getType() == ConnectivityManager.TYPE_WIMAX
				|| activeNetwork.getType() == ConnectivityManager.TYPE_BLUETOOTH
				|| activeNetwork.getType() == ConnectivityManager.TYPE_ETHERNET);
	}
}
 
Example 5
Source File: RunConditionMonitor.java    From syncthing-android with Mozilla Public License 2.0 6 votes vote down vote up
private boolean isMobileDataConnection() {
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    if (ni == null) {
        // In flight mode.
        return false;
    }
    if (!ni.isConnected()) {
        // No network connection.
        return false;
    }
    switch (ni.getType()) {
        case ConnectivityManager.TYPE_BLUETOOTH:
        case ConnectivityManager.TYPE_MOBILE:
        case ConnectivityManager.TYPE_MOBILE_DUN:
        case ConnectivityManager.TYPE_MOBILE_HIPRI:
            return true;
        default:
            return false;
    }
}
 
Example 6
Source File: NetworkChangeNotifierAutoDetect.java    From 365browser with Apache License 2.0 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 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: 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 9
Source File: NetWorkUtils.java    From Simpler with Apache License 2.0 5 votes vote down vote up
/**
 * 判断当前网络的类型是否是蓝牙
 *
 * @param context 上下文
 * @return 当前网络的类型是否是蓝牙。false:当前没有网络连接或者网络类型不是蓝牙
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public static boolean isBluetoothByType(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        return false;
    }
    else {
        return getCurrentNetworkType(context) ==
                ConnectivityManager.TYPE_BLUETOOTH;
    }
}
 
Example 10
Source File: MediaConsentUtils.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if media can be streamed on the active network
 * without requiring user consent.
 */
public static boolean canStreamMedia(Context context) {
    NetworkInfo info = NetworkUtil.getNetworkInfo(context);
    if (info == null || !info.isConnected()) return false;
    switch (info.getType()) {
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_BLUETOOTH:
        case ConnectivityManager.TYPE_ETHERNET:
            return true;
        default:
            return !MainApplication.getEnvironment(context).getUserPrefs().isDownloadOverWifiOnly() ||
                    NetworkUtil.isOnZeroRatedNetwork(context, config);
    }
}
 
Example 11
Source File: JoH.java    From xDrip 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 12
Source File: JoH.java    From xDrip 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 13
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 14
Source File: OfflinePageUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** Returns the NCN network type corresponding to the connectivity manager network type */
protected int convertAndroidNetworkTypeToConnectionType(int connectivityManagerNetworkType) {
    if (connectivityManagerNetworkType == ConnectivityManager.TYPE_WIFI) {
        return ConnectionType.CONNECTION_WIFI;
    }
    // for mobile, we don't know if it is 2G, 3G, or 4G, default to worst case of 2G.
    if (connectivityManagerNetworkType == ConnectivityManager.TYPE_MOBILE) {
        return ConnectionType.CONNECTION_2G;
    }
    if (connectivityManagerNetworkType == ConnectivityManager.TYPE_BLUETOOTH) {
        return ConnectionType.CONNECTION_BLUETOOTH;
    }
    // Since NetworkConnectivityManager doesn't understand the other types, call them UNKNOWN.
    return ConnectionType.CONNECTION_UNKNOWN;
}
 
Example 15
Source File: DownloaderService.java    From QtAndroidTools with MIT License 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 16
Source File: NetworkChangeNotifierAutoDetect.java    From cronet with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Returns the connection subtype for the given NetworkState.
 */
public int getConnectionSubtype() {
    if (!isConnected()) {
        return ConnectionSubtype.SUBTYPE_NONE;
    }

    switch (getNetworkType()) {
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_WIMAX:
        case ConnectivityManager.TYPE_BLUETOOTH:
            return ConnectionSubtype.SUBTYPE_UNKNOWN;
        case ConnectivityManager.TYPE_MOBILE:
            // Use information from TelephonyManager to classify the connection.
            switch (getNetworkSubType()) {
                case TelephonyManager.NETWORK_TYPE_GPRS:
                    return ConnectionSubtype.SUBTYPE_GPRS;
                case TelephonyManager.NETWORK_TYPE_EDGE:
                    return ConnectionSubtype.SUBTYPE_EDGE;
                case TelephonyManager.NETWORK_TYPE_CDMA:
                    return ConnectionSubtype.SUBTYPE_CDMA;
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                    return ConnectionSubtype.SUBTYPE_1XRTT;
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    return ConnectionSubtype.SUBTYPE_IDEN;
                case TelephonyManager.NETWORK_TYPE_UMTS:
                    return ConnectionSubtype.SUBTYPE_UMTS;
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                    return ConnectionSubtype.SUBTYPE_EVDO_REV_0;
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                    return ConnectionSubtype.SUBTYPE_EVDO_REV_A;
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                    return ConnectionSubtype.SUBTYPE_HSDPA;
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                    return ConnectionSubtype.SUBTYPE_HSUPA;
                case TelephonyManager.NETWORK_TYPE_HSPA:
                    return ConnectionSubtype.SUBTYPE_HSPA;
                case TelephonyManager.NETWORK_TYPE_EVDO_B:
                    return ConnectionSubtype.SUBTYPE_EVDO_REV_B;
                case TelephonyManager.NETWORK_TYPE_EHRPD:
                    return ConnectionSubtype.SUBTYPE_EHRPD;
                case TelephonyManager.NETWORK_TYPE_HSPAP:
                    return ConnectionSubtype.SUBTYPE_HSPAP;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return ConnectionSubtype.SUBTYPE_LTE;
                default:
                    return ConnectionSubtype.SUBTYPE_UNKNOWN;
            }
        default:
            return ConnectionSubtype.SUBTYPE_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: NetworkChangeNotifierAutoDetect.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the connection subtype for the given NetworkState.
 */
public int getConnectionSubtype() {
    if (!isConnected()) {
        return ConnectionSubtype.SUBTYPE_NONE;
    }

    switch (getNetworkType()) {
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_WIMAX:
        case ConnectivityManager.TYPE_BLUETOOTH:
            return ConnectionSubtype.SUBTYPE_UNKNOWN;
        case ConnectivityManager.TYPE_MOBILE:
            // Use information from TelephonyManager to classify the connection.
            switch (getNetworkSubType()) {
                case TelephonyManager.NETWORK_TYPE_GPRS:
                    return ConnectionSubtype.SUBTYPE_GPRS;
                case TelephonyManager.NETWORK_TYPE_EDGE:
                    return ConnectionSubtype.SUBTYPE_EDGE;
                case TelephonyManager.NETWORK_TYPE_CDMA:
                    return ConnectionSubtype.SUBTYPE_CDMA;
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                    return ConnectionSubtype.SUBTYPE_1XRTT;
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    return ConnectionSubtype.SUBTYPE_IDEN;
                case TelephonyManager.NETWORK_TYPE_UMTS:
                    return ConnectionSubtype.SUBTYPE_UMTS;
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                    return ConnectionSubtype.SUBTYPE_EVDO_REV_0;
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                    return ConnectionSubtype.SUBTYPE_EVDO_REV_A;
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                    return ConnectionSubtype.SUBTYPE_HSDPA;
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                    return ConnectionSubtype.SUBTYPE_HSUPA;
                case TelephonyManager.NETWORK_TYPE_HSPA:
                    return ConnectionSubtype.SUBTYPE_HSPA;
                case TelephonyManager.NETWORK_TYPE_EVDO_B:
                    return ConnectionSubtype.SUBTYPE_EVDO_REV_B;
                case TelephonyManager.NETWORK_TYPE_EHRPD:
                    return ConnectionSubtype.SUBTYPE_EHRPD;
                case TelephonyManager.NETWORK_TYPE_HSPAP:
                    return ConnectionSubtype.SUBTYPE_HSPAP;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return ConnectionSubtype.SUBTYPE_LTE;
                default:
                    return ConnectionSubtype.SUBTYPE_UNKNOWN;
            }
        default:
            return ConnectionSubtype.SUBTYPE_UNKNOWN;
    }
}
 
Example 19
Source File: InformationCollector.java    From open-rmbt with Apache License 2.0 4 votes vote down vote up
/** Returns the network that the phone is on (e.g. Wifi, Edge, GPRS, etc). */
public int getNetwork()
{
    int result = TelephonyManager.NETWORK_TYPE_UNKNOWN;
    
    if (connManager != null)
    {
        final NetworkInfo activeNetworkInfo = connManager.getActiveNetworkInfo();
        if (activeNetworkInfo != null)
        {
            final int type = activeNetworkInfo.getType();
            switch (type)
            {
            case ConnectivityManager.TYPE_WIFI:
                result = NETWORK_WIFI;
                break;
                
            case ConnectivityManager.TYPE_BLUETOOTH:
                result = NETWORK_BLUETOOTH;
                break;
                
            case ConnectivityManager.TYPE_ETHERNET:
                result = NETWORK_ETHERNET;
                break;
                
            case ConnectivityManager.TYPE_MOBILE:
            case ConnectivityManager.TYPE_MOBILE_DUN:
            case ConnectivityManager.TYPE_MOBILE_HIPRI:
            case ConnectivityManager.TYPE_MOBILE_MMS:
            case ConnectivityManager.TYPE_MOBILE_SUPL:
                result = telManager.getNetworkType();
                break;
            }
        }
    }
    
    /* detect change from wifi to mobile or reverse */
    final int lastNetworkType = this.lastNetworkType.get();
    if (result != TelephonyManager.NETWORK_TYPE_UNKNOWN && lastNetworkType != TelephonyManager.NETWORK_TYPE_UNKNOWN)
    {
        if (
            (result == NETWORK_WIFI && lastNetworkType != NETWORK_WIFI)
                ||
            (result != NETWORK_WIFI && lastNetworkType == NETWORK_WIFI)
            )
            illegalNetworkTypeChangeDetcted.set(true);
    }
    if (result != lastNetworkType)
    {
        this.lastNetworkType.set(result);
        if (telListener != null)
            telListener.onSignalStrengthsChanged(null);
    }
        
    return result;
}
 
Example 20
Source File: NetworkMonitorAutoDetect.java    From webrtc_android with MIT License 4 votes vote down vote up
private static ConnectionType getConnectionType(
    boolean isConnected, int networkType, int networkSubtype) {
  if (!isConnected) {
    return ConnectionType.CONNECTION_NONE;
  }

  switch (networkType) {
    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 (networkSubtype) {
        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_CELLULAR;
      }
    case ConnectivityManager.TYPE_VPN:
      return ConnectionType.CONNECTION_VPN;
    default:
      return ConnectionType.CONNECTION_UNKNOWN;
  }
}