android.net.NetworkInfo

Here are the examples of the java api class android.net.NetworkInfo taken from open source projects.

1. WifiStateChangeReceiver#onReceive()

Project: swiftp
File: WifiStateChangeReceiver.java
@Override
public void onReceive(Context context, Intent intent) {
    NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
    if (info == null) {
        Cat.e("Null network info received, bailing");
        return;
    }
    if (info.isConnected()) {
        Cat.d("We are connecting to a wifi network");
        Intent startServerIntent = new Intent(context, StartServerService.class);
        context.startService(startServerIntent);
    } else {
        Cat.d("We are disconnected from wifi network");
        Intent stopServerIntent = new Intent(context, StopServerService.class);
        context.startService(stopServerIntent);
    }
}

2. NetUtil#getNetworkIsConnected()

Project: RxjavaRetrofit
File: NetUtil.java
/**
     * ????????
     *
     * @param context
     *            ???
     * @return ??????true??????false
     */
public static boolean getNetworkIsConnected(Context context) {
    // ?????????
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    // ??????null???false
    if (manager == null) {
        return false;
    }
    // ???????????
    NetworkInfo info = manager.getActiveNetworkInfo();
    // ???????null???false
    if (info == null) {
        return false;
    }
    // ????????
    return info.isConnected();
}

3. NetworkAvailabliltyCheck#getNetworkAvailable()

Project: osmdroid
File: NetworkAvailabliltyCheck.java
@Override
public boolean getNetworkAvailable() {
    if (!mHasNetworkStatePermission) {
        // if we're unable to check network state, assume we have a network
        return true;
    }
    final NetworkInfo networkInfo = mConnectionManager.getActiveNetworkInfo();
    if (networkInfo == null) {
        return false;
    }
    if (networkInfo.isAvailable()) {
        return true;
    }
    return mIsX86 && networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET;
}

4. NetworkUtil#hasInternet()

Project: narrate-android
File: NetworkUtil.java
public static boolean hasInternet() {
    NetworkInfo info = (NetworkInfo) ((ConnectivityManager) GlobalApplication.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
    if (info == null || !info.isConnected()) {
        return false;
    }
    if (info.isRoaming()) {
        // disable internet while roaming, just return false
        return false;
    }
    return true;
}

5. Network#isWifi()

Project: EverMemo
File: Network.java
public static boolean isWifi(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (mWifi.isConnected()) {
        return true;
    } else {
        return false;
    }
}

6. MainActivity#isNetworkAvailable()

Project: arcgis-runtime-samples-android
File: MainActivity.java
/**
   * Returns true if a data connection is currently available.
   * 
   * @return true if a data connection is available.
   */
public boolean isNetworkAvailable() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    // Check cellular data connection.
    NetworkInfo mobileNi = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (mobileNi != null && mobileNi.getState() == State.CONNECTED) {
        return true;
    }
    // Check wifi connection
    NetworkInfo wifiNi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNi != null && wifiNi.getState() == State.CONNECTED) {
        return true;
    }
    return false;
}

7. GDBUtil#hasInternet()

Project: arcgis-runtime-samples-android
File: GDBUtil.java
/**
   * Checks whether the device is connected to a network
   */
public static boolean hasInternet(Activity a) {
    boolean hasConnectedWifi = false;
    boolean hasConnectedMobile = false;
    ConnectivityManager cm = (ConnectivityManager) a.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("wifi"))
            if (ni.isConnected())
                hasConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("mobile"))
            if (ni.isConnected())
                hasConnectedMobile = true;
    }
    return hasConnectedWifi || hasConnectedMobile;
}

8. NetworkUtils#isWifiConnected()

Project: AnimeTaste
File: NetworkUtils.java
/**
	 * make true current connect service is wifi
	 * 
	 * @param mContext
	 * @return
	 */
public static boolean isWifiConnected(Context mContext) {
    ConnectivityManager connManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (mWifi.isConnected()) {
        return true;
    } else {
        return false;
    }
}

9. ImapConnection#shouldEnableCompression()

Project: k-9
File: ImapConnection.java
private boolean shouldEnableCompression() {
    boolean useCompression = true;
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo != null) {
        int type = networkInfo.getType();
        if (K9MailLib.isDebug()) {
            Log.d(LOG_TAG, "On network type " + type);
        }
        NetworkType networkType = NetworkType.fromConnectivityManagerType(type);
        useCompression = settings.useCompression(networkType);
    }
    if (K9MailLib.isDebug()) {
        Log.d(LOG_TAG, "useCompression " + useCompression);
    }
    return useCompression;
}

10. Utility#hasConnectivity()

Project: k-9
File: Utility.java
/**
     * Check to see if we have network connectivity.
     */
public static boolean hasConnectivity(final Context context) {
    final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager == null) {
        return false;
    }
    final NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo();
    if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) {
        return true;
    } else {
        return false;
    }
}

11. AboutFragment#buildContent()

Project: iBeebo
File: AboutFragment.java
private String buildContent() {
    String network = "";
    ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            network = "Wifi";
        } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            int subType = networkInfo.getSubtype();
            if (subType == TelephonyManager.NETWORK_TYPE_GPRS) {
                network = "GPRS";
            }
        }
    }
    return "@andforce #iBeebo#?? " + android.os.Build.MANUFACTURER + " " + android.os.Build.MODEL + ",Android " + android.os.Build.VERSION.RELEASE + "," + network + " version:" + buildVersionInfo();
}

12. WifiNetworkUtil#isConnected()

Project: gpslogger
File: WifiNetworkUtil.java
@Override
public boolean isConnected(Context context) {
    if (Systems.isDozing(context)) {
        return false;
    }
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    boolean isWifiRequired = PreferenceHelper.getInstance().shouldAutoSendOnWifiOnly();
    boolean isDeviceOnWifi = true;
    if (isWifiRequired && netInfo != null) {
        isDeviceOnWifi = (netInfo.getType() == ConnectivityManager.TYPE_WIFI);
    }
    return netInfo != null && netInfo.isConnectedOrConnecting() && isDeviceOnWifi;
}

13. UiUtils#downloadNeedsWarning()

Project: gh4a
File: UiUtils.java
@SuppressLint("NewApi")
public static boolean downloadNeedsWarning(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        return cm.isActiveNetworkMetered();
    }
    NetworkInfo info = cm.getActiveNetworkInfo();
    return info == null || info.getType() != ConnectivityManager.TYPE_WIFI;
}

14. NetworkStateUtils#getNetworkType()

Project: ExhibitionCenter
File: NetworkStateUtils.java
/**
     * ????????
     *
     * @return 0?????   1?WIFI??   2?WAP??    3?NET??
     */
public static int getNetworkType(Context context) {
    int netType = 0;
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo == null) {
        return netType;
    }
    int nType = networkInfo.getType();
    if (nType == ConnectivityManager.TYPE_MOBILE) {
        String extraInfo = networkInfo.getExtraInfo();
        if (extraInfo != null && !extraInfo.isEmpty()) {
            if (extraInfo.toLowerCase().equals("cmnet")) {
                netType = NET_TYPE_NET;
            } else {
                netType = NET_TYPE_WAP;
            }
        }
    } else if (nType == ConnectivityManager.TYPE_WIFI) {
        netType = NET_TYPE_WIFI;
    }
    return netType;
}

15. NetworkStatusManager#getNetworkType()

Project: cube-sdk
File: NetworkStatusManager.java
/**
     * 2G/3G/4G/WIFI
     *
     * @return
     */
public int getNetworkType() {
    NetworkInfo activeNetworkInfo = getNetworkInfo();
    if (activeNetworkInfo != null) {
        // WIFI
        if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            return NETWORK_CLASS_WIFI;
        } else // MOBILE
        if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            return getMobileNetworkClass(activeNetworkInfo.getSubtype());
        }
    }
    return NETWORK_CLASS_UNKNOWN;
}

16. AndroidImplementation#setCurrentAccessPoint()

Project: CodenameOne
File: AndroidImplementation.java
/**
     * @inheritDoc
     */
public void setCurrentAccessPoint(String id) {
    if (apIds == null) {
        getAPIds();
    }
    NetworkInfo info = (NetworkInfo) apIds.get(id);
    if (info == null || info.isConnectedOrConnecting()) {
        return;
    }
    ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    cm.setNetworkPreference(info.getType());
}

17. AndroidImplementation#getCurrentAccessPoint()

Project: CodenameOne
File: AndroidImplementation.java
public String getCurrentAccessPoint() {
    ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info == null) {
        return null;
    }
    String apName = info.getTypeName() + "_" + info.getSubtypeName();
    if (info.getExtraInfo() != null) {
        apName += "_" + info.getExtraInfo();
    }
    return apName;
}

18. ConnectivityManagerCompatHoneycombMR2#isActiveNetworkMetered()

Project: CodenameOne
File: ConnectivityManagerCompatHoneycombMR2.java
public static boolean isActiveNetworkMetered(ConnectivityManager cm) {
    final NetworkInfo info = cm.getActiveNetworkInfo();
    if (info == null) {
        // err on side of caution
        return true;
    }
    final int type = info.getType();
    switch(type) {
        case TYPE_MOBILE:
        case TYPE_MOBILE_DUN:
        case TYPE_MOBILE_HIPRI:
        case TYPE_MOBILE_MMS:
        case TYPE_MOBILE_SUPL:
        case TYPE_WIMAX:
            return true;
        case TYPE_WIFI:
        case TYPE_BLUETOOTH:
        case TYPE_ETHERNET:
            return false;
        default:
            // err on side of caution
            return true;
    }
}

19. ConnectivityManagerCompatGingerbread#isActiveNetworkMetered()

Project: CodenameOne
File: ConnectivityManagerCompatGingerbread.java
public static boolean isActiveNetworkMetered(ConnectivityManager cm) {
    final NetworkInfo info = cm.getActiveNetworkInfo();
    if (info == null) {
        // err on side of caution
        return true;
    }
    final int type = info.getType();
    switch(type) {
        case TYPE_MOBILE:
        case TYPE_MOBILE_DUN:
        case TYPE_MOBILE_HIPRI:
        case TYPE_MOBILE_MMS:
        case TYPE_MOBILE_SUPL:
        case TYPE_WIMAX:
            return true;
        case TYPE_WIFI:
            return false;
        default:
            // err on side of caution
            return true;
    }
}

20. ImApp#isNetworkAvailableAndConnected()

Project: ChatSecureAndroid
File: ImApp.java
//   public boolean isBackgroundDataEnabled() { //"background data" is a deprectaed concept
public static boolean isNetworkAvailableAndConnected(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo nInfo = manager.getActiveNetworkInfo();
    if (nInfo != null) {
        Log.d(LOG_TAG, "isNetworkAvailableAndConnected? available=" + nInfo.isAvailable() + " connected=" + nInfo.isConnected());
        return nInfo.isAvailable() && nInfo.isConnected();
    } else
        //no network info is a bad idea
        return false;
}

21. NetworkReceiver#onReceive()

Project: browser-android
File: NetworkReceiver.java
@Override
public void onReceive(Context context, Intent intent) {
    ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = conn.getActiveNetworkInfo();
    // If there is a connection reload the webivew.
    if (networkInfo != null) {
        mWebRenderer.reload();
        try {
            // We had a crash here "Receiver not registered"
            context.unregisterReceiver(this);
        } catch (IllegalArgumentException exc) {
            exc.printStackTrace();
        }
    }
}

22. NetworkUtils#getConnectivityStatus()

Project: AnimeTaste
File: NetworkUtils.java
public static int getConnectivityStatus(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (null != activeNetwork) {
        if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
            return TYPE_WIFI;
        if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE)
            return TYPE_MOBILE;
    }
    return TYPE_NOT_CONNECTED;
}

23. TDevice#getNetworkType()

Project: AndroidReview
File: TDevice.java
/**
     * ????????
     *
     * @return 0????? 1?WIFI?? 2?WAP?? 3?NET??
     */
public static int getNetworkType() {
    int netType = 0;
    ConnectivityManager connectivityManager = (ConnectivityManager) AppContext.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo == null) {
        return netType;
    }
    int nType = networkInfo.getType();
    if (nType == ConnectivityManager.TYPE_MOBILE) {
        String extraInfo = networkInfo.getExtraInfo();
        if (!TextUtils.isEmpty(extraInfo)) {
            if (extraInfo.toLowerCase().equals("cmnet")) {
                netType = NETTYPE_CMNET;
            } else {
                netType = NETTYPE_CMWAP;
            }
        }
    } else if (nType == ConnectivityManager.TYPE_WIFI) {
        netType = NETTYPE_WIFI;
    }
    return netType;
}

24. TDevice#isWifiOpen()

Project: AndroidReview
File: TDevice.java
public static boolean isWifiOpen() {
    boolean isWifiConnect = false;
    ConnectivityManager cm = (ConnectivityManager) BaseApplication.context().getSystemService(Context.CONNECTIVITY_SERVICE);
    // check the networkInfos numbers
    NetworkInfo[] networkInfos = cm.getAllNetworkInfo();
    for (int i = 0; i < networkInfos.length; i++) {
        if (networkInfos[i].getState() == NetworkInfo.State.CONNECTED) {
            if (networkInfos[i].getType() == ConnectivityManager.TYPE_MOBILE) {
                isWifiConnect = false;
            }
            if (networkInfos[i].getType() == ConnectivityManager.TYPE_WIFI) {
                isWifiConnect = true;
            }
        }
    }
    return isWifiConnect;
}

25. NetworkUtil#isMobileNetwork()

Project: android-wail-app
File: NetworkUtil.java
public static boolean isMobileNetwork(Context context) {
    if (!isAvailable(context)) {
        return false;
    }
    final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    return networkInfo != null && networkInfo.isConnectedOrConnecting();
}

26. Utils#isInternetAvailable()

Project: android-utils
File: Utils.java
/**
     * Checks if the Internet connection is available.
     *
     * @return Returns true if the Internet connection is available. False otherwise.
     **/
public static boolean isInternetAvailable(Context ctx) {
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    // otherwise check if we are connected
    if (networkInfo != null && networkInfo.isConnected()) {
        return true;
    }
    return false;
}

27. ProxyUtils#isConnectedToWiFi()

Project: android-proxy
File: ProxyUtils.java
public static Boolean isConnectedToWiFi() {
    NetworkInfo ni = ProxyUtils.getCurrentWiFiInfo();
    if (ni != null && ni.isAvailable() && ni.isConnected()) {
        return true;
    } else {
        return false;
    }
}

28. BasicMediaPlayerTestCaseBase#checkOnlineConnectionStates()

Project: android-openslmediaplayer
File: BasicMediaPlayerTestCaseBase.java
protected void checkOnlineConnectionStates() {
    // Check WiFi connection is enabled
    ConnectivityManager connManager = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    // NetworkInfo mobile =
    // connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    assertTrue("WiFi is not enabled", wifi.isConnected());
// assertFalse("Mobile communication is enabled", mobile.isConnected());
}

29. NetworkUtils#getNetworkType()

Project: Android-Next
File: NetworkUtils.java
/**
     * ????????
     *
     * @return ??????
     */
public static NetworkType getNetworkType(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo info = cm.getActiveNetworkInfo();
    if (info == null || !info.isConnectedOrConnecting()) {
        return NetworkType.NONE;
    }
    int type = info.getType();
    if (ConnectivityManager.TYPE_WIFI == type) {
        return NetworkType.WIFI;
    } else if (ConnectivityManager.TYPE_MOBILE == type) {
        return NetworkType.MOBILE;
    } else {
        return NetworkType.OTHER;
    }
}

30. Network#getConnectedType()

Project: android-lite-http
File: Network.java
public static NetType getConnectedType(Context context) {
    NetworkInfo net = getConnManager(context).getActiveNetworkInfo();
    if (net != null) {
        switch(net.getType()) {
            case ConnectivityManager.TYPE_WIFI:
                return NetType.Wifi;
            case ConnectivityManager.TYPE_MOBILE:
                return NetType.Mobile;
            default:
                return NetType.Other;
        }
    }
    return NetType.None;
}

31. Network#getConnectedType()

Project: android-lite-http
File: Network.java
public static NetType getConnectedType(Context context) {
    NetworkInfo net = getConnManager(context).getActiveNetworkInfo();
    if (net != null) {
        switch(net.getType()) {
            case ConnectivityManager.TYPE_WIFI:
                return NetType.Wifi;
            case ConnectivityManager.TYPE_MOBILE:
                return NetType.Mobile;
            default:
                return NetType.Other;
        }
    }
    return NetType.None;
}

32. Network#getConnectedType()

Project: android-common
File: Network.java
public static NetType getConnectedType(Context context) {
    NetworkInfo net = getConnectivityManager(context).getActiveNetworkInfo();
    if (net != null) {
        switch(net.getType()) {
            case ConnectivityManager.TYPE_WIFI:
                return NetType.Wifi;
            case ConnectivityManager.TYPE_MOBILE:
                return NetType.Mobile;
            default:
                return NetType.Other;
        }
    }
    return NetType.None;
}

33. SegmentIntegrationTest#flushWhenDisconnectedSkipsUpload()

Project: analytics-android
File: SegmentIntegrationTest.java
@Test
public void flushWhenDisconnectedSkipsUpload() throws IOException {
    NetworkInfo networkInfo = mock(NetworkInfo.class);
    when(networkInfo.isConnectedOrConnecting()).thenReturn(false);
    ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
    when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);
    Context context = mockApplication();
    when(context.getSystemService(CONNECTIVITY_SERVICE)).thenReturn(connectivityManager);
    Client client = mock(Client.class);
    SegmentIntegration segmentIntegration = new SegmentBuilder().context(context).client(client).build();
    segmentIntegration.submitFlush();
    verify(client, never()).upload();
}

34. NetUtil#getCurrentActiveNetworkInfo()

Project: YiBo
File: NetUtil.java
private static NetworkInfo getCurrentActiveNetworkInfo(Context context) {
    NetworkInfo networkInfo = null;
    // ????????????????wi-fi,net,gsm,cdma???????
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager != null) {
        networkInfo = connectivityManager.getActiveNetworkInfo();
        Logger.debug("Current Active Network :{}", networkInfo);
    }
    return networkInfo;
}

35. YaximBroadcastReceiver#initNetworkStatus()

Project: yaxim
File: YaximBroadcastReceiver.java
public static void initNetworkStatus(Context context) {
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    networkType = -1;
    if (networkInfo != null) {
        Log.d(TAG, "Init: ACTIVE NetworkInfo: " + networkInfo.toString());
        if (networkInfo.isConnected()) {
            networkType = networkInfo.getType();
        }
    }
    Log.d(TAG, "initNetworkStatus -> " + networkType);
}

36. AboutFragment#buildContent()

Project: weiciyuan
File: AboutFragment.java
private String buildContent() {
    String network = "";
    ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            network = "Wifi";
        } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            int subType = networkInfo.getSubtype();
            if (subType == TelephonyManager.NETWORK_TYPE_GPRS) {
                network = "GPRS";
            }
        }
    }
    return "@???App #???App??# " + android.os.Build.MANUFACTURER + " " + android.os.Build.MODEL + ",Android " + android.os.Build.VERSION.RELEASE + "," + network + " version:" + buildVersionInfo();
}

37. SpotifyMediaPlayer#updateBitrate()

Project: tomahawk-android
File: SpotifyMediaPlayer.java
public void updateBitrate() {
    ConnectivityManager conMan = (ConnectivityManager) TomahawkApp.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = conMan.getActiveNetworkInfo();
    if (netInfo != null && netInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        Log.d(TAG, "Updating bitrate to HIGH, because we have a Wifi connection");
        setBitrate(PreferenceUtils.PREF_BITRATE_HIGH);
    } else {
        Log.d(TAG, "Updating bitrate to user setting, because we don't have a Wifi connection");
        int prefbitrate = PreferenceUtils.getInt(PreferenceUtils.PREF_BITRATE);
        setBitrate(prefbitrate);
    }
}

38. ConnectivityWire#postEvent()

Project: tinybus
File: ConnectivityWire.java
void postEvent() {
    if (mConnectivityManager == null) {
        mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    }
    NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
    if (mpProducedEventClass.equals(ConnectionStateEvent.class)) {
        mConnectionStateEvent = new ConnectionStateEvent(networkInfo);
        bus.post(mConnectionStateEvent);
    } else {
        mConnectionEvent = new ConnectionEvent(networkInfo);
        bus.post(mConnectionEvent);
    }
}

39. NetworkReceiver#onReceive()

Project: syncthing-android
File: NetworkReceiver.java
@Override
public void onReceive(Context context, Intent intent) {
    if (!ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction()))
        return;
    if (!SyncthingService.alwaysRunInBackground(context))
        return;
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    boolean isWifiConnected = wifiInfo != null && wifiInfo.isConnected();
    Log.v(TAG, "Received wifi " + (isWifiConnected ? "connected" : "disconnected") + " event");
    Intent i = new Intent(context, SyncthingService.class);
    i.putExtra(DeviceStateHolder.EXTRA_HAS_WIFI, isWifiConnected);
    context.startService(i);
}

40. Utility#isConnected()

Project: SMSSync
File: Utility.java
/**
     * Checks if there is Internet connection or data connection on the device.
     *
     * @param context - The activity calling this method.
     * @return boolean
     */
public static boolean isConnected(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivity.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnectedOrConnecting()) {
        return true;
    }
    return false;
}

41. Utility#isConnected()

Project: SMSSync
File: Utility.java
/**
     * Checks if there is Internet connection or data connection on the device.
     *
     * @param context - The activity calling this method.
     * @return boolean
     */
public static boolean isConnected(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivity.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnectedOrConnecting()) {
        return true;
    }
    return false;
}

42. NetUtils#getAPNType()

Project: SimplifyReader
File: NetUtils.java
public static NetType getAPNType(Context context) {
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo == null) {
        return NetType.NONE;
    }
    int nType = networkInfo.getType();
    if (nType == ConnectivityManager.TYPE_MOBILE) {
        if (networkInfo.getExtraInfo().toLowerCase(Locale.getDefault()).equals("cmnet")) {
            return NetType.CMNET;
        } else {
            return NetType.CMWAP;
        }
    } else if (nType == ConnectivityManager.TYPE_WIFI) {
        return NetType.WIFI;
    }
    return NetType.NONE;
}

43. NetUtils#isNetworkAvailable()

Project: SimplifyReader
File: NetUtils.java
public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] info = mgr.getAllNetworkInfo();
    if (info != null) {
        for (int i = 0; i < info.length; i++) {
            if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                return true;
            }
        }
    }
    return false;
}

44. HomeActivity#checkConnectivity()

Project: sbt-android
File: HomeActivity.java
private void checkConnectivity() {
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    boolean connected = activeNetworkInfo != null && activeNetworkInfo.isConnected();
    if (!connected) {
        loading.setVisibility(View.GONE);
        ViewStub stub = (ViewStub) findViewById(R.id.stub_no_connection);
        ImageView iv = (ImageView) stub.inflate();
        final AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getDrawable(R.drawable.avd_no_connection);
        iv.setImageDrawable(avd);
        avd.start();
    }
}

45. NetUtil#isWiFi()

Project: RxjavaRetrofit
File: NetUtil.java
/**
     * ????
     *
     * @param context
     * @return true ???false ??
     */
public static boolean isWiFi(Context context) {
    ConnectivityManager connectMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = connectMgr.getActiveNetworkInfo();
    if (info == null) {
        return false;
    } else {
        if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            return true;
        } else {
            return false;
        }
    }
}

46. NetworkMonitor#isConnectedToiWiFi()

Project: RoMote
File: NetworkMonitor.java
public boolean isConnectedToiWiFi() {
    if (mCm == null) {
        return false;
    }
    NetworkInfo activeNetwork = mCm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    if (isConnected) {
        return activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
    }
    return false;
}

47. ConfigureDeviceFragment#getWirelessNetworkName()

Project: RoMote
File: ConfigureDeviceFragment.java
private String getWirelessNetworkName(Context context) {
    String networkName = "";
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm == null) {
        return networkName;
    }
    final NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    boolean isWiFi = activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
    if (isConnected && isWiFi) {
        final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
        networkName = connectionInfo.getSSID();
    }
    return networkName;
}

48. ReactiveNetwork#getConnectivityStatus()

Project: ReactiveNetwork
File: ReactiveNetwork.java
/**
   * Gets current network connectivity status
   *
   * @param context Application Context is recommended here
   * @return ConnectivityStatus, which can be WIFI_CONNECTED, MOBILE_CONNECTED or OFFLINE
   */
public ConnectivityStatus getConnectivityStatus(final Context context) {
    final String service = Context.CONNECTIVITY_SERVICE;
    final ConnectivityManager manager = (ConnectivityManager) context.getSystemService(service);
    final NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    if (networkInfo == null) {
        return ConnectivityStatus.OFFLINE;
    }
    if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return ConnectivityStatus.WIFI_CONNECTED;
    } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        return ConnectivityStatus.MOBILE_CONNECTED;
    }
    return ConnectivityStatus.OFFLINE;
}

49. ADAppUtil#getNetWorkStatus()

Project: QDNews
File: ADAppUtil.java
/**
     * ??????????????
     * 0???
     * 1?WIFI
     * 2?2G
     * 3?3G
     * 4?4G
     *
     * @return ?????2G?3G?4G?WIFI
     */
public static int getNetWorkStatus(Context context) {
    int netWorkType = Constants.NETWORK_CLASS_UNKNOWN;
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        int type = networkInfo.getType();
        if (type == ConnectivityManager.TYPE_WIFI) {
            netWorkType = Constants.NETWORK_WIFI;
        } else if (type == ConnectivityManager.TYPE_MOBILE) {
            netWorkType = getNetWorkClass(context);
        }
    }
    return netWorkType;
}

50. NetworkChangeReceiver#isActiveConnection()

Project: q-municate-android
File: NetworkChangeReceiver.java
private boolean isActiveConnection(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
    if (activeNetworkInfo != null) {
        int type = activeNetworkInfo.getType();
        if (type == ConnectivityManager.TYPE_WIFI || type == ConnectivityManager.TYPE_MOBILE) {
            return activeNetworkInfo.isConnected();
        }
    }
    return false;
}

51. HomeActivity#checkConnectivity()

Project: plaid
File: HomeActivity.java
private void checkConnectivity() {
    final ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    connected = activeNetworkInfo != null && activeNetworkInfo.isConnected();
    if (!connected) {
        loading.setVisibility(View.GONE);
        if (noConnection == null) {
            final ViewStub stub = (ViewStub) findViewById(R.id.stub_no_connection);
            noConnection = (ImageView) stub.inflate();
        }
        final AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getDrawable(R.drawable.avd_no_connection);
        noConnection.setImageDrawable(avd);
        avd.start();
        connectivityManager.registerNetworkCallback(new NetworkRequest.Builder().addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build(), connectivityCallback);
        monitoringConnectivity = true;
    }
}

52. DispatcherTest#performNetworkStateChangeFlushesFailedHunters()

Project: picasso
File: DispatcherTest.java
@Test
public void performNetworkStateChangeFlushesFailedHunters() {
    PicassoExecutorService service = mock(PicassoExecutorService.class);
    NetworkInfo info = mockNetworkInfo(true);
    Dispatcher dispatcher = createDispatcher(service);
    Action failedAction1 = mockAction(URI_KEY_1, URI_1);
    Action failedAction2 = mockAction(URI_KEY_2, URI_2);
    dispatcher.failedActions.put(URI_KEY_1, failedAction1);
    dispatcher.failedActions.put(URI_KEY_2, failedAction2);
    dispatcher.performNetworkStateChange(info);
    verify(service, times(2)).submit(any(BitmapHunter.class));
    assertThat(dispatcher.failedActions).isEmpty();
}

53. DispatcherTest#performRetryMarksForReplayIfSupportsReplayAndNoConnectivity()

Project: picasso
File: DispatcherTest.java
@Test
public void performRetryMarksForReplayIfSupportsReplayAndNoConnectivity() {
    NetworkInfo networkInfo = mockNetworkInfo(false);
    Action action = mockAction(URI_KEY_1, URI_1, mockTarget());
    BitmapHunter hunter = mockHunter(URI_KEY_1, bitmap1, false, action);
    when(hunter.shouldRetry(anyBoolean(), any(NetworkInfo.class))).thenReturn(true);
    when(hunter.supportsReplay()).thenReturn(true);
    when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);
    dispatcher.performRetry(hunter);
    assertThat(dispatcher.hunterMap).isEmpty();
    assertThat(dispatcher.failedActions).hasSize(1);
    verify(service, never()).submit(hunter);
}

54. DispatcherTest#performRetryMarksForReplayIfSupportedScansNetworkChangesAndShouldNotRetry()

Project: picasso
File: DispatcherTest.java
@Test
public void performRetryMarksForReplayIfSupportedScansNetworkChangesAndShouldNotRetry() {
    NetworkInfo networkInfo = mockNetworkInfo(true);
    Action action = mockAction(URI_KEY_1, URI_1, mockTarget());
    BitmapHunter hunter = mockHunter(URI_KEY_1, bitmap1, false, action);
    when(hunter.supportsReplay()).thenReturn(true);
    when(hunter.shouldRetry(anyBoolean(), any(NetworkInfo.class))).thenReturn(false);
    when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);
    dispatcher.performRetry(hunter);
    assertThat(dispatcher.hunterMap).isEmpty();
    assertThat(dispatcher.failedActions).hasSize(1);
    verify(service, never()).submit(hunter);
}

55. NetworkReceiver#onReceive()

Project: open-keychain
File: NetworkReceiver.java
@Override
public void onReceive(Context context, Intent intent) {
    ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = conn.getActiveNetworkInfo();
    boolean isTypeWifi = (networkInfo != null) && (networkInfo.getType() == ConnectivityManager.TYPE_WIFI);
    boolean isConnected = (networkInfo != null) && networkInfo.isConnected();
    if (isTypeWifi && isConnected) {
        // broadcaster receiver disabled
        setWifiReceiverComponent(false, context);
        Intent serviceIntent = new Intent(context, KeyserverSyncAdapterService.class);
        serviceIntent.setAction(KeyserverSyncAdapterService.ACTION_SYNC_NOW);
        context.startService(serviceIntent);
    }
}

56. VDMobileUtil#getMobileDetail()

Project: NewsMe
File: VDMobileUtil.java
public static int getMobileDetail(Context context) {
    ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (conn == null) {
        return NONE;
    }
    NetworkInfo networkInfo = conn.getActiveNetworkInfo();
    if (networkInfo == null) {
        // ?????
        return NONE;
    }
    if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return WIFI;
    } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return telephonyManager.getNetworkType();
    }
    return NONE;
}

57. AndroidUtil#isNetworkConnectedBy3G()

Project: NewsMe
File: AndroidUtil.java
/**
	 * ??????3G??
	 * 
	 * @param context
	 * @return
	 */
public static boolean isNetworkConnectedBy3G(Context context) {
    NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (networkInfo != null && networkInfo.isConnected()) {
        int subtype = networkInfo.getSubtype();
        if (subtype == TelephonyManager.NETWORK_TYPE_EVDO_A || subtype == TelephonyManager.NETWORK_TYPE_EVDO_0 || subtype == TelephonyManager.NETWORK_TYPE_UMTS || subtype == // ?????3G
        TelephonyManager.NETWORK_TYPE_HSPA) {
            return true;
        }
    }
    return false;
}

58. AndroidUtil#isNetworkConnectedBy2G()

Project: NewsMe
File: AndroidUtil.java
/**
	 * ??????2G??
	 * 
	 * @param context
	 * @return
	 */
public static boolean isNetworkConnectedBy2G(Context context) {
    NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (networkInfo != null && networkInfo.isConnected()) {
        int subtype = networkInfo.getSubtype();
        if (subtype == TelephonyManager.NETWORK_TYPE_GPRS || subtype == TelephonyManager.NETWORK_TYPE_EDGE || subtype == // ?????2G
        TelephonyManager.NETWORK_TYPE_CDMA) {
            return true;
        }
    }
    return false;
}

59. NetworkConnectionChangeReceiver#getConnectivityStatus()

Project: NetworkEvents
File: NetworkConnectionChangeReceiver.java
private ConnectivityStatus getConnectivityStatus(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo != null) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            return ConnectivityStatus.WIFI_CONNECTED;
        } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            return ConnectivityStatus.MOBILE_CONNECTED;
        }
    }
    return ConnectivityStatus.OFFLINE;
}

60. NetUtils#isNetworkConnected()

Project: MousePaint
File: NetUtils.java
/**
	 * ?????? ?toast??
	 * 
	 * @return
	 */
public static boolean isNetworkConnected(Context context) {
    ConnectivityManager con = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkinfo = con.getActiveNetworkInfo();
    if (networkinfo == null || !networkinfo.isAvailable()) {
        // ???????
        Toast.makeText(context.getApplicationContext(), "??????", Toast.LENGTH_SHORT).show();
        return false;
    }
    boolean wifi = con.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
    return true;
}

61. MainActivity#isInternetAvailable()

Project: mintube
File: MainActivity.java
public static boolean isInternetAvailable(Context context) {
    NetworkInfo info = (NetworkInfo) ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
    if (info == null) {
        Log.d("Network Test", "no internet connection");
        return false;
    } else {
        if (info.isConnected()) {
            Log.d("Network Test", " internet connection available...");
            return true;
        } else {
            Log.d("Network Test", " internet connection");
            return true;
        }
    }
}

62. FordDemoUtil#isConnectedToInternet()

Project: mHealth-App
File: FordDemoUtil.java
public boolean isConnectedToInternet(Context context) {
    AppLog.enter(TAG, AppLog.getMethodName());
    boolean result = false;
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        result = true;
    } else {
        result = false;
    }
    AppLog.exit(TAG, AppLog.getMethodName());
    return result;
}

63. NetWorkUtils#getNetWorkType()

Project: meiShi
File: NetWorkUtils.java
/**
     * ????????
     *
     * @param context
     * @return -1 ????
     * 0 ????;
     * 1 wifi;
     * 2 ???
     * @throws Exception
     */
public static int getNetWorkType(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (activeNetwork == null)
        return -1;
    if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
        return 1;
    } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
        return 0;
    } else {
        return 2;
    }
}

64. Network#getConnectedType()

Project: MarkdownEditors
File: Network.java
public NetType getConnectedType() {
    NetworkInfo net = getConnectivityManager().getActiveNetworkInfo();
    if (net != null) {
        switch(net.getType()) {
            case ConnectivityManager.TYPE_WIFI:
                return NetType.Wifi;
            case ConnectivityManager.TYPE_MOBILE:
                return NetType.Mobile;
            default:
                return NetType.Other;
        }
    }
    return NetType.None;
}

65. ConnectivityUtils#isNetworkConnected()

Project: quickblox-android-sdk
File: ConnectivityUtils.java
public static boolean isNetworkConnected() {
    ConnectivityManager connectivityManager = (ConnectivityManager) CoreApp.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    NetworkInfo mobile = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    NetworkInfo bluetooth = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_BLUETOOTH);
    NetworkInfo wimax = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIMAX);
    if (wifi == null && mobile == null && bluetooth == null && wimax == null) {
        return false;
    }
    if (wifi != null && wifi.isConnected()) {
        return true;
    }
    if (mobile != null && mobile.isConnected()) {
        return true;
    }
    if (bluetooth != null && bluetooth.isConnected()) {
        return true;
    }
    if (wimax != null && wimax.isConnected()) {
        return true;
    }
    return false;
}

66. ApolloUtils#isOnline()

Project: frostwire-android
File: ApolloUtils.java
/**
     * Used to determine if there is an active data connection and what type of
     * connection it is if there is one
     * 
     * @param context The {@link Context} to use
     * @return True if there is an active data connection, false otherwise.
     *         Also, if the user has checked to only download via Wi-Fi in the
     *         settings, the mobile data and other network connections aren't
     *         returned at all
     */
public static final boolean isOnline(final Context context) {
    // aldenml: this nulls the feature of online download of music data
    if (true) {
        return false;
    }
    /*
         * This sort of handles a sudden configuration change, but I think it
         * should be dealt with in a more professional way.
         */
    if (context == null) {
        return false;
    }
    boolean state = false;
    final boolean onlyOnWifi = PreferenceUtils.getInstance(context).onlyOnWifi();
    /* Monitor network connections */
    final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    /* Wi-Fi connection */
    final NetworkInfo wifiNetwork = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNetwork != null) {
        state = wifiNetwork.isConnectedOrConnecting();
    }
    /* Mobile data connection */
    final NetworkInfo mbobileNetwork = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (mbobileNetwork != null) {
        if (!onlyOnWifi) {
            state = mbobileNetwork.isConnectedOrConnecting();
        }
    }
    /* Other networks */
    final NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    if (activeNetwork != null) {
        if (!onlyOnWifi) {
            state = activeNetwork.isConnectedOrConnecting();
        }
    }
    return state;
}

67. HttpAccess#onReceive()

Project: SalesforceMobileSDK-Android
File: HttpAccess.java
/**
     * Detects network changes and sets the network connectivity status.
     *
     * @param context The context of the request.
     * @param intent Intent.
     */
@Override
public void onReceive(Context context, Intent intent) {
    if (conMgr == null) {
        return;
    }
    // Checks if an active network is available.
    final NetworkInfo activeInfo = conMgr.getActiveNetworkInfo();
    if (activeInfo != null && activeInfo.isConnected()) {
        setHasNetwork(true);
        return;
    }
    // Tries WIFI data connection.
    final NetworkInfo wifiInfo = conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiInfo != null && wifiInfo.isConnected()) {
        setHasNetwork(true);
        return;
    }
    // Tries mobile connection.
    final NetworkInfo mobileInfo = conMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (mobileInfo == null) {
        setHasNetwork(false);
        return;
    }
}

68. JCUtils#isWifiConnected()

Project: JieCaoVideoPlayer-develop
File: JCUtils.java
public static boolean isWifiConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNetworkInfo.isConnected()) {
        return true;
    }
    return false;
}

69. JCUtils#isWifiConnected()

Project: JieCaoVideoPlayer
File: JCUtils.java
public static boolean isWifiConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNetworkInfo.isConnected()) {
        return true;
    }
    return false;
}

70. NetWorkUtil#isWifiConnected()

Project: JianDanRxJava
File: NetWorkUtil.java
/**
	 * ??????????????WIFI
	 *
	 * @param context
	 * @return
	 */
public static boolean isWifiConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return wifiNetworkInfo.isConnected();
}

71. NetWorkUtil#isWifiConnected()

Project: JianDan
File: NetWorkUtil.java
/**
	 * ??????????????WIFI
	 *
	 * @param context
	 * @return
	 */
public static boolean isWifiConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return wifiNetworkInfo.isConnected();
}

72. NetworkUtils#getNetType()

Project: HeaderAndFooterRecyclerView
File: NetworkUtils.java
/**
     * ???????? ??2??wifi,1??2G/3G
     *
     * @param paramContext
     * @return
     */
public static String[] getNetType(Context paramContext) {
    String[] arrayOfString = { "Unknown", "Unknown" };
    PackageManager localPackageManager = paramContext.getPackageManager();
    if (localPackageManager.checkPermission("android.permission.ACCESS_NETWORK_STATE", paramContext.getPackageName()) != 0) {
        arrayOfString[0] = "Unknown";
        return arrayOfString;
    }
    ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext.getSystemService("connectivity");
    if (localConnectivityManager == null) {
        arrayOfString[0] = "Unknown";
        return arrayOfString;
    }
    NetworkInfo localNetworkInfo1 = localConnectivityManager.getNetworkInfo(1);
    if (localNetworkInfo1 != null && localNetworkInfo1.getState() == NetworkInfo.State.CONNECTED) {
        arrayOfString[0] = "2";
        return arrayOfString;
    }
    NetworkInfo localNetworkInfo2 = localConnectivityManager.getNetworkInfo(0);
    if (localNetworkInfo2 != null && localNetworkInfo2.getState() == NetworkInfo.State.CONNECTED) {
        arrayOfString[0] = "1";
        arrayOfString[1] = localNetworkInfo2.getSubtypeName();
        return arrayOfString;
    }
    return arrayOfString;
}

73. NetworkUtils#connectedToWifi()

Project: AntennaPod
File: NetworkUtils.java
public static boolean connectedToWifi() {
    ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return mWifi.isConnected();
}

74. NetWorkUtils#checkEthernet()

Project: Android-tv-widget
File: NetWorkUtils.java
/**
	 * ??????.
	 */
public static boolean checkEthernet(Context context) {
    ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = conn.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
    return networkInfo.isConnected();
}

75. InterfaceTracker#getInterfaceDetails()

Project: afwall
File: InterfaceTracker.java
private static InterfaceDetails getInterfaceDetails(Context context) {
    InterfaceDetails ret = new InterfaceDetails();
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info == null || info.isConnected() == false) {
        return ret;
    }
    switch(info.getType()) {
        case ConnectivityManager.TYPE_MOBILE:
        case ConnectivityManager.TYPE_MOBILE_DUN:
        case ConnectivityManager.TYPE_MOBILE_HIPRI:
        case ConnectivityManager.TYPE_MOBILE_MMS:
        case ConnectivityManager.TYPE_MOBILE_SUPL:
        case ConnectivityManager.TYPE_WIMAX:
            ret.isRoaming = info.isRoaming();
            ret.netType = ConnectivityManager.TYPE_MOBILE;
            ret.netEnabled = true;
            break;
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_BLUETOOTH:
        case ConnectivityManager.TYPE_ETHERNET:
            ret.netType = ConnectivityManager.TYPE_WIFI;
            ret.netEnabled = true;
            break;
    }
    getTetherStatus(context, ret);
    NewInterfaceScanner.populateLanMasks(context, ITFS_WIFI, ret);
    return ret;
}

76. NetWorkUtil#isWifiConnected()

Project: YiRan
File: NetWorkUtil.java
/**
     * ??????????????WIFI
     *
     * @param context
     * @return
     */
public static boolean isWifiConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return wifiNetworkInfo.isConnected();
}

77. NetworkChecker#isConnectedToWifiNetwork()

Project: yahnac
File: NetworkChecker.java
private boolean isConnectedToWifiNetwork() {
    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return networkInfo.isConnected();
}

78. NetworkUtils#getActiveNetworkType()

Project: WordPress-Android
File: NetworkUtils.java
/**
     * returns the ConnectivityManager.TYPE_xxx if there's an active connection, otherwise
     * returns TYPE_UNKNOWN
     */
private static int getActiveNetworkType(Context context) {
    NetworkInfo info = getActiveNetworkInfo(context);
    if (info == null || !info.isConnected()) {
        return TYPE_UNKNOWN;
    }
    return info.getType();
}

79. FileUploaderTask#hasDataConnection()

Project: wigle-wifi-wardriving
File: FileUploaderTask.java
public static boolean hasDataConnection(final Context context) {
    final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    final NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    //noinspection SimplifiableIfStatement
    if (wifi != null && wifi.isAvailable()) {
        return true;
    }
    return mobile != null && mobile.isAvailable();
}

80. WifiUtils#isWifiConnect()

Project: WifiChat
File: WifiUtils.java
/**
     * ???????wifi
     * 
     * @return boolean?(isConnect),?????(true)????(false)
     */
public static boolean isWifiConnect() {
    NetworkInfo mNetworkInfo = ((ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return mNetworkInfo.isConnected();
}

81. RxWifiManagerTest#networkStateChanges()

Project: rx-receivers
File: RxWifiManagerTest.java
//
@SuppressWarnings("ResourceType")
//
@Test
public void networkStateChanges() throws IllegalAccessException, InstantiationException {
    Application application = RuntimeEnvironment.application;
    TestSubscriber<NetworkStateChangedEvent> o = new TestSubscriber<>();
    RxWifiManager.networkStateChanges(application).subscribe(o);
    o.assertValues();
    NetworkInfo networkInfo1 = NetworkInfo.class.newInstance();
    WifiInfo wifiInfo1 = WifiInfo.class.newInstance();
    Intent intent1 = //
    new Intent(NETWORK_STATE_CHANGED_ACTION).putExtra(WifiManager.EXTRA_NETWORK_INFO, networkInfo1).putExtra(WifiManager.EXTRA_BSSID, "foo").putExtra(WifiManager.EXTRA_WIFI_INFO, wifiInfo1);
    application.sendBroadcast(intent1);
    NetworkStateChangedEvent event1 = NetworkStateChangedEvent.create(networkInfo1, "foo", wifiInfo1);
    o.assertValues(event1);
    NetworkInfo networkInfo2 = NetworkInfo.class.newInstance();
    Intent intent2 = //
    new Intent(NETWORK_STATE_CHANGED_ACTION).putExtra(WifiManager.EXTRA_NETWORK_INFO, networkInfo2);
    application.sendBroadcast(intent2);
    NetworkStateChangedEvent event2 = NetworkStateChangedEvent.create(networkInfo2, null, null);
    o.assertValues(event1, event2);
}

82. DefaultNetworkStateChecker#isNetworkAvailable()

Project: robospice
File: DefaultNetworkStateChecker.java
@Override
public boolean isNetworkAvailable(final Context context) {
    final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo[] allNetworkInfos = connectivityManager.getAllNetworkInfo();
    for (final NetworkInfo networkInfo : allNetworkInfos) {
        if (networkInfo.getState() == NetworkInfo.State.CONNECTED || networkInfo.getState() == NetworkInfo.State.CONNECTING) {
            return true;
        }
    }
    return false;
}

83. ADAppUtil#isWifiConnected()

Project: QDNews
File: ADAppUtil.java
/**
     * ???????wifi??
     *
     * @param context
     * @return
     */
public static boolean isWifiConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNetworkInfo.isConnected()) {
        return true;
    }
    return false;
}

84. Util#getNetworkInfo()

Project: NetGuard
File: Util.java
public static String getNetworkInfo(Context context) {
    StringBuilder sb = new StringBuilder();
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ani = cm.getActiveNetworkInfo();
    List<NetworkInfo> listNI = new ArrayList<>();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        listNI.addAll(Arrays.asList(cm.getAllNetworkInfo()));
    else
        for (Network network : cm.getAllNetworks()) {
            NetworkInfo ni = cm.getNetworkInfo(network);
            if (ni != null)
                listNI.add(ni);
        }
    for (NetworkInfo ni : listNI) {
        sb.append(ni.getTypeName()).append('/').append(ni.getSubtypeName()).append(' ').append(ni.getDetailedState()).append(TextUtils.isEmpty(ni.getExtraInfo()) ? "" : " " + ni.getExtraInfo()).append(ni.getType() == ConnectivityManager.TYPE_MOBILE ? " " + Util.getNetworkGeneration(ni.getSubtype()) : "").append(ni.isRoaming() ? " R" : "").append(ani != null && ni.getType() == ani.getType() && ni.getSubtype() == ani.getSubtype() ? " *" : "").append("\r\n");
    }
    try {
        Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
        if (nis != null)
            while (nis.hasMoreElements()) {
                NetworkInterface ni = nis.nextElement();
                if (ni != null && !"lo".equals(ni.getName())) {
                    List<InterfaceAddress> ias = ni.getInterfaceAddresses();
                    if (ias != null)
                        for (InterfaceAddress ia : ias) sb.append(ni.getName()).append(' ').append(ia.getAddress().getHostAddress()).append('/').append(ia.getNetworkPrefixLength()).append(' ').append(ni.getMTU()).append("\r\n");
                }
            }
    } catch (Throwable ex) {
        sb.append(ex.toString()).append("\r\n");
    }
    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);
    return sb.toString();
}

85. NetworkUtil#isOnWifi()

Project: narrate-android
File: NetworkUtil.java
public static boolean isOnWifi() {
    NetworkInfo info = (NetworkInfo) ((ConnectivityManager) GlobalApplication.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (info == null)
        return false;
    return info.isConnected();
}

86. MerlinsBeard#getMobileNetworkSubtypeName()

Project: merlin
File: MerlinsBeard.java
/**
     * Provides a human-readable String describing the network subtype (e.g. UMTS, LTE) when connected to a mobile network.
     *
     * @return network subtype name, or empty string if not connected to a mobile network.
     */
public String getMobileNetworkSubtypeName() {
    NetworkInfo networkInfo = getNetworkInfo();
    if (networkInfo == null || !networkInfo.isConnected()) {
        return "";
    }
    return networkInfo.getSubtypeName();
}

87. ConnectivityUtils#isConnectedWifi()

Project: YourAppIdea
File: ConnectivityUtils.java
public static boolean isConnectedWifi(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
}

88. ConnectivityUtils#isConnected()

Project: YourAppIdea
File: ConnectivityUtils.java
public static boolean isConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}

89. NetWorkUtil#isNetWorkConnected()

Project: YiRan
File: NetWorkUtil.java
/**
     * ???????????
     *
     * @param context
     * @return
     */
public static boolean isNetWorkConnected(Context context) {
    boolean result;
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    result = netInfo != null && netInfo.isConnected();
    return result;
}

90. NetUtil#updateNetworkConfig()

Project: YiBo
File: NetUtil.java
/**
	 * ??????????????????
	 *
	 * @param context
	 */
public static void updateNetworkConfig(Context context) {
    boolean isNetWap = false;
    NetType type = getCurrentNetType(context);
    if (type == NetType.NONE) {
        return;
    }
    String proxyHost = null;
    int proxyPort = 0;
    String proxyUser = null;
    String proxyPassword = null;
    NetworkInfo networkInfo = getCurrentActiveNetworkInfo(context);
    if (networkInfo == null) {
        return;
    }
    if (type == NetType.MOBILE_EDGE || type == NetType.MOBILE_GPRS || type == NetType.MOBILE_3G) {
        String apnName = networkInfo.getExtraInfo();
        Logger.debug("extraInfo:{}", apnName);
        // ??????????APN????????????????????
        if (StringUtil.isNotEmpty(apnName) && !(Build.VERSION.SDK_INT >= 17)) {
            String[] projection = { "apn", "proxy", "port", "user", "password" };
            Cursor cursor = context.getContentResolver().query(PREFER_APN_CONTENT_URI, projection, null, null, null);
            if (cursor != null && cursor.moveToFirst()) {
                int apnIndex = cursor.getColumnIndex("apn");
                int proxyIndex = cursor.getColumnIndex("proxy");
                int portIndex = cursor.getColumnIndex("port");
                int userIndex = cursor.getColumnIndex("user");
                int passwordIndex = cursor.getColumnIndex("password");
                while (!cursor.isAfterLast()) {
                    if (apnName.equals(cursor.getString(apnIndex))) {
                        proxyHost = cursor.getString(proxyIndex);
                        proxyPort = cursor.getInt(portIndex);
                        proxyUser = cursor.getString(userIndex);
                        proxyPassword = cursor.getString(passwordIndex);
                        //????wap??????10.0.0.172?80????wap????10.0.0.200?80?
                        isNetWap = "10.0.0.172".equals(proxyHost) || "10.0.0.200".equals(proxyHost);
                    }
                    cursor.moveToNext();
                }
            }
        }
    }
    if (isNETWAP ^ isNetWap) {
        HttpRequestHelper.setGlobalProxy(proxyHost, proxyPort, proxyUser, proxyPassword);
        isNETWAP = isNetWap;
    }
    if (Logger.isDebug()) {
        Toast.makeText(context, "Network switch to " + type + " , CMWAP = " + isNETWAP + ", Proxy = " + proxyHost, Toast.LENGTH_SHORT).show();
    }
}

91. NetUtil#getCurrentNetType()

Project: YiBo
File: NetUtil.java
public static NetType getCurrentNetType(Context context) {
    NetType type = NetType.NONE;
    // ?????????
    NetworkInfo info = getCurrentActiveNetworkInfo(context);
    if (info == null) {
        return type;
    }
    // ????????????
    if (info.getState() == NetworkInfo.State.CONNECTED) {
        if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            type = NetType.WIFI;
        } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
            String subTypeName = info.getSubtypeName().toUpperCase();
            if (subTypeName.indexOf("GPRS") > -1) {
                type = NetType.MOBILE_GPRS;
            } else if (subTypeName.indexOf("EDGE") > -1) {
                type = NetType.MOBILE_EDGE;
            } else {
                type = NetType.MOBILE_3G;
            }
        } else {
            type = NetType.UNKNOW;
        }
    } else if (info.getState() == NetworkInfo.State.CONNECTING) {
        type = NetType.UNKNOW;
        System.out.println("connecting " + info.getType());
    }
    return type;
}

92. NetUtil#isConnect()

Project: YiBo
File: NetUtil.java
/**
	 * ???????????????????AndroidManifest.xml?????
	 *
	 * @param context
	 * @return true : ??????
	 * @return false : ??????
	 **/
public static boolean isConnect(Context context) {
    NetworkInfo info = getCurrentActiveNetworkInfo(context);
    return info != null && info.getState() == NetworkInfo.State.CONNECTED;
}

93. XMPPService#networkConnectedOrConnecting()

Project: yaxim
File: XMPPService.java
private boolean networkConnectedOrConnecting() {
    NetworkInfo info = getNetworkInfo();
    return info != null && info.isConnectedOrConnecting();
}

94. XMPPService#networkConnected()

Project: yaxim
File: XMPPService.java
private boolean networkConnected() {
    NetworkInfo info = getNetworkInfo();
    return info != null && info.isConnected();
}

95. NetworkUtils#isNetworkAvailable()

Project: WordPress-Android
File: NetworkUtils.java
/**
     * returns true if a network connection is available
     */
public static boolean isNetworkAvailable(Context context) {
    NetworkInfo info = getActiveNetworkInfo(context);
    return (info != null && info.isConnected());
}

96. UtilsNetwork#isNetworkAvailable()

Project: WhatsAppBetaUpdater
File: UtilsNetwork.java
public static Boolean isNetworkAvailable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null;
}

97. Utility#isGprs()

Project: weiciyuan
File: Utility.java
public static boolean isGprs(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        if (networkInfo.getType() != ConnectivityManager.TYPE_WIFI) {
            return true;
        }
    }
    return false;
}

98. Utility#getNetType()

Project: weiciyuan
File: Utility.java
public static int getNetType(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        return networkInfo.getType();
    }
    return -1;
}

99. Utility#isWifi()

Project: weiciyuan
File: Utility.java
public static boolean isWifi(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            return true;
        }
    }
    return false;
}

100. Utility#isConnected()

Project: weiciyuan
File: Utility.java
public static boolean isConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnected();
}