android.net.ConnectivityManager

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

1. AppService#bringUpCellularNetwork()

Project: Tower
File: AppService.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void bringUpCellularNetwork(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        return;
    Timber.i("Setting up cellular network request.");
    final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkRequest networkReq = new NetworkRequest.Builder().addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR).build();
    connMgr.requestNetwork(networkReq, new ConnectivityManager.NetworkCallback() {

        @Override
        public void onAvailable(Network network) {
            Timber.i("Setting up process default network: %s", network);
            ConnectivityManager.setProcessDefaultNetwork(network);
            DroidPlannerApp.setCellularNetworkAvailability(true);
        }
    });
}

2. 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());
}

3. 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;
}

4. 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);
}

5. 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();
}

6. NetUtil#getNetworkState()

Project: WayHoo
File: NetUtil.java
public static int getNetworkState(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    // Wifi
    State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    if (state == State.CONNECTED || state == State.CONNECTING) {
        return NETWORN_WIFI;
    }
    // 3G
    state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
    if (state == State.CONNECTED || state == State.CONNECTING) {
        return NETWORN_MOBILE;
    }
    return NETWORN_NONE;
}

7. NetUtil#getNetworkState()

Project: WayHoo
File: NetUtil.java
public static int getNetworkState(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    // Wifi
    State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    if (state == State.CONNECTED || state == State.CONNECTING) {
        return NETWORN_WIFI;
    }
    // 3G
    state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
    if (state == State.CONNECTED || state == State.CONNECTING) {
        return NETWORN_MOBILE;
    }
    return NETWORN_NONE;
}

8. AndroidDevices#hasLANConnection()

Project: VCL-Android
File: AndroidDevices.java
public static boolean hasLANConnection() {
    boolean networkEnabled = false;
    ConnectivityManager connectivity = (ConnectivityManager) (VLCApplication.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE));
    if (connectivity != null) {
        NetworkInfo networkInfo = connectivity.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected() && (networkInfo.getType() != ConnectivityManager.TYPE_MOBILE)) {
            networkEnabled = true;
        }
    }
    return networkEnabled;
}

9. Util#isConnected()

Project: Ushahidi_Android
File: Util.java
/**
     * Is there internet connection
     */
public static boolean isConnected(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    networkInfo = connectivity.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected() && networkInfo.isAvailable()) {
        return true;
    }
    return false;
}

10. 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);
    }
}

11. 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);
}

12. 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;
}

13. 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;
}

14. 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;
}

15. 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;
}

16. MyUtils#isMobileDataEnabled()

Project: SimplePomodoro-android
File: MyUtils.java
/**
	 * @return null if unconfirmed
	 */
public static Boolean isMobileDataEnabled(Context paramContext) {
    Object connectivityService = paramContext.getSystemService("connectivity");
    ConnectivityManager cm = (ConnectivityManager) connectivityService;
    try {
        Class<?> c = Class.forName(cm.getClass().getName());
        Method m = c.getDeclaredMethod("getMobileDataEnabled");
        m.setAccessible(true);
        return (Boolean) m.invoke(cm);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

17. ToolsUtil#isNetworkAvailable()

Project: SimpleNews
File: ToolsUtil.java
/**
	 * ????????
	 * @param context
	 * @return
	 */
public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm != null) {
        //?????????????
        //????? cm.getActiveNetworkInfo().isAvailable();
        NetworkInfo[] info = cm.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
        }
    }
    return false;
}

18. 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();
    }
}

19. 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;
        }
    }
}

20. 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();
}

21. NetUtil#getNetworkState()

Project: RxjavaRetrofit
File: NetUtil.java
/**
     * ??????
     *
     * @param context
     * @return
     */
public static int getNetworkState(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    // Wifi
    NetworkInfo.State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING) {
        return NETWORN_WIFI;
    }
    // 3G
    state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
    if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING) {
        return NETWORN_MOBILE;
    }
    return NETWORN_NONE;
}

22. NetworkUtil#checkInternetIsActive()

Project: RxAndroidBootstrap
File: NetworkUtil.java
/**
     * Checks the internet is active.
     * @param context
     * @return
     */
public static boolean checkInternetIsActive(Context context) {
    ConnectivityManager connec = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    android.net.NetworkInfo wifi = connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    android.net.NetworkInfo mobile = connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (wifi.isConnected() || mobile.isConnected()) {
        return true;
    }
    return false;
}

23. 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;
}

24. SystemUtils#setMobileData()

Project: robotium
File: SystemUtils.java
/**
	 * Sets if mobile data should be turned on or off. Requires android.permission.CHANGE_NETWORK_STATE in the AndroidManifest.xml of the application under test.
	 * 
	 * @param turnedOn true if mobile data is to be turned on and false if not
	 */
public void setMobileData(Boolean turnedOn) {
    ConnectivityManager dataManager = (ConnectivityManager) instrumentation.getTargetContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    Method dataClass = null;
    try {
        dataClass = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
        dataClass.setAccessible(true);
        dataClass.invoke(dataManager, turnedOn);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

25. 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;
}

26. Utils#isMobileDataEnabled()

Project: qksms
File: Utils.java
/**
     * Checks whether or not mobile data is enabled and returns the result
     *
     * @param context is the context of the activity or service
     * @return true if data is enabled or false if disabled
     */
public static Boolean isMobileDataEnabled(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    try {
        Class<?> c = Class.forName(cm.getClass().getName());
        Method m = c.getDeclaredMethod("getMobileDataEnabled");
        m.setAccessible(true);
        return (Boolean) m.invoke(cm);
    } catch (Exception e) {
        Log.e(TAG, "exception thrown", e);
        return Boolean.FALSE;
    }
}

27. 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;
}

28. 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;
}

29. 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;
    }
}

30. 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);
    }
}

31. 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;
}

32. 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;
}

33. NetworkUtil#checkInternetIsActive()

Project: MVPAndroidBootstrap
File: NetworkUtil.java
/**
     * Checks the internet is active.
     * @param context
     * @return
     */
public static boolean checkInternetIsActive(Context context) {
    ConnectivityManager connec = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    android.net.NetworkInfo wifi = connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    android.net.NetworkInfo mobile = connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (wifi.isConnected() || mobile.isConnected()) {
        return true;
    }
    return false;
}

34. NetworkInfoTest#testIsConnectedWithGlobal()

Project: MozStumbler
File: NetworkInfoTest.java
@Test
@Config(shadows = { MyShadowConnectivityManager.class })
public void testIsConnectedWithGlobal() {
    NetworkInfo ni = new NetworkInfo(ctx);
    ConnectivityManager connectivityManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    MyShadowConnectivityManager shadowConnManager = (MyShadowConnectivityManager) shadowOf(connectivityManager);
    assertFalse(ni.isConnected());
    shadowConnManager.setConnectedFlag(true);
    assertTrue(ni.isConnected());
}

35. 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;
}

36. OrgUtils#isMobileOnline()

Project: mobileorg-android
File: OrgUtils.java
public static boolean isMobileOnline(Context context) {
    ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    State mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
    if (mobile == NetworkInfo.State.CONNECTED)
        return true;
    else
        return false;
}

37. OrgUtils#isWifiOnline()

Project: mobileorg-android
File: OrgUtils.java
public static boolean isWifiOnline(Context context) {
    ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    if (wifi == NetworkInfo.State.CONNECTED)
        return true;
    else
        return false;
}

38. 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;
}

39. 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;
    }
}

40. Network#printNetworkInfo()

Project: MarkdownEditors
File: Network.java
/**
     * ??????????
     *
     * @return boolean
     */
public boolean printNetworkInfo() {
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo in = connectivity.getActiveNetworkInfo();
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                // if (info[i].getType() == ConnectivityManager.TYPE_WIFI) {
                Log.i(TAG, "NetworkInfo[" + i + "]isAvailable : " + info[i].isAvailable());
                Log.i(TAG, "NetworkInfo[" + i + "]isConnected : " + info[i].isConnected());
                Log.i(TAG, "NetworkInfo[" + i + "]isConnectedOrConnecting : " + info[i].isConnectedOrConnecting());
                Log.i(TAG, "NetworkInfo[" + i + "]: " + info[i]);
            // }
            }
            Log.i(TAG, "\n");
        } else {
            Log.i(TAG, "getAllNetworkInfo is null");
        }
    }
    return false;
}

41. NetCheck#isNetConnected()

Project: LinLock
File: NetCheck.java
/**
     * ????????
     *
     * @return
     */
public static boolean isNetConnected() {
    ConnectivityManager cm = (ConnectivityManager) App.get().getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm != null) {
        NetworkInfo[] infos = cm.getAllNetworkInfo();
        if (infos != null) {
            for (NetworkInfo ni : infos) {
                if (ni.isConnected()) {
                    return true;
                }
            }
        }
    }
    return false;
}

42. GlobalConfig#isNetworkAvailable()

Project: light-novel-library_Wenku8_Android
File: GlobalConfig.java
public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm != null) {
        NetworkInfo[] info = cm.getAllNetworkInfo();
        if (info != null) {
            for (NetworkInfo ni : info) {
                if (ni.getState() == NetworkInfo.State.CONNECTED)
                    return true;
            }
        }
    }
    return false;
}

43. HttpUtil#readNetworkState()

Project: Leisure
File: HttpUtil.java
public static boolean readNetworkState() {
    ConnectivityManager cm = (ConnectivityManager) LeisureApplication.AppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm != null && cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected()) {
        isWIFI = (cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI);
        return true;
    } else {
        return false;
    }
}

44. 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;
    }
}

45. ConnectionInfo#isConnectingToInternet()

Project: incubator-taverna-mobile
File: ConnectionInfo.java
public boolean isConnectingToInternet() {
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null)
            for (int i = 0; i < info.length; i++) {
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
    }
    return false;
}

46. 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();
}

47. 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;
}

48. 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;
}

49. 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;
}

50. 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;
    }
}

51. PhoneStateReceiver#isLocalNetworkConnected()

Project: dmix
File: PhoneStateReceiver.java
private static boolean isLocalNetworkConnected() {
    final ConnectivityManager cm = (ConnectivityManager) APP.getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean isLocalNetwork = false;
    if (cm != null) {
        final NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        if (networkInfo != null) {
            final int networkType = networkInfo.getType();
            if (networkInfo.isConnected() && networkType == ConnectivityManager.TYPE_WIFI || networkType == ConnectivityManager.TYPE_ETHERNET) {
                isLocalNetwork = true;
            }
        }
    }
    return isLocalNetwork;
}

52. DNSHelper#getDnsServers()

Project: Conversations
File: DNSHelper.java
@TargetApi(21)
private static List<InetAddress> getDnsServers(Context context) {
    List<InetAddress> servers = new ArrayList<>();
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    Network[] networks = connectivityManager == null ? null : connectivityManager.getAllNetworks();
    if (networks == null) {
        return getDnsServersPreLollipop();
    }
    for (int i = 0; i < networks.length; ++i) {
        LinkProperties linkProperties = connectivityManager.getLinkProperties(networks[i]);
        if (linkProperties != null) {
            if (hasDefaultRoute(linkProperties)) {
                servers.addAll(0, getIPv4First(linkProperties.getDnsServers()));
            } else {
                servers.addAll(getIPv4First(linkProperties.getDnsServers()));
            }
        }
    }
    if (servers.size() > 0) {
        Log.d(Config.LOGTAG, "used lollipop variant to discover dns servers in " + networks.length + " networks");
    }
    return servers.size() > 0 ? servers : getDnsServersPreLollipop();
}

53. 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;
}

54. 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;
}

55. 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();
        }
    }
}

56. AnalyticsEvent#getNetworkType()

Project: braintree_android
File: AnalyticsEvent.java
private String getNetworkType(Context context) {
    String networkType = null;
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager.getActiveNetworkInfo() != null) {
        networkType = connectivityManager.getActiveNetworkInfo().getTypeName();
    }
    if (networkType == null) {
        networkType = "none";
    }
    return networkType;
}

57. Utils#isNetworkAvailable()

Project: Book-Catalogue
File: Utils.java
/*
	 *@return boolean return true if the application can access the internet
	 */
public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
        }
    }
    return false;
}

58. Device#getIdentifiers()

Project: BambooPlayer
File: Device.java
@SuppressLint("NewApi")
public static String getIdentifiers(Context ctx) {
    StringBuilder sb = new StringBuilder();
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO)
        sb.append(getPair("serial", Build.SERIAL));
    else
        sb.append(getPair("serial", "No Serial"));
    sb.append(getPair("android_id", Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID)));
    TelephonyManager tel = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    sb.append(getPair("sim_country_iso", tel.getSimCountryIso()));
    sb.append(getPair("network_operator_name", tel.getNetworkOperatorName()));
    sb.append(getPair("unique_id", Crypto.md5(sb.toString())));
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    sb.append(getPair("network_type", cm.getActiveNetworkInfo() == null ? "-1" : String.valueOf(cm.getActiveNetworkInfo().getType())));
    return sb.toString();
}

59. 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;
}

60. 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;
}

61. UtilsLibrary#isNetworkAvailable()

Project: AppUpdater
File: UtilsLibrary.java
static Boolean isNetworkAvailable(Context context) {
    Boolean res = false;
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm != null) {
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        if (networkInfo != null) {
            res = networkInfo.isConnected();
        }
    }
    return res;
}

62. CommonUtility#isNetworkAvailable()

Project: appcan-android
File: CommonUtility.java
/**
     * ???????android.permission.ACCESS_NETWORK_STATE
     */
public static boolean isNetworkAvailable(Context context) {
    boolean isAvailable = false;
    ConnectivityManager cm = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm != null) {
        NetworkInfo info = cm.getActiveNetworkInfo();
        if (info != null && info.isAvailable()) {
            isAvailable = true;
        }
    }
    return isAvailable;
}

63. 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;
}

64. 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;
    }
}

65. NetUtil#isNetworkAvailable()

Project: AndroidStudyDemo
File: NetUtil.java
/**
     * ??????????,????????
     *
     * @param context ???
     * @return ????
     */
public static boolean isNetworkAvailable(Context context) {
    boolean netstate = false;
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                if (info[i].getState() == State.CONNECTED) {
                    netstate = true;
                    break;
                }
            }
        }
    }
    return netstate;
}

66. 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;
}

67. 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;
}

68. web#hasInternetConnection()

Project: AndroidQuickUtils
File: web.java
/**
     * Checks if the app has connectivity to the Internet
     *
     * @return true if has connection to the Internet and false if it doesn't
     */
public static boolean hasInternetConnection() {
    ConnectivityManager connectivity = (ConnectivityManager) QuickUtils.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        return false;
    } else {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
        }
    }
    return false;
}

69. 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();
}

70. Utils#getDataConnectionType()

Project: android-utils
File: Utils.java
/**
     * Checks the type of data connection that is currently available on the device.
     *
     * @return <code>ConnectivityManager.TYPE_*</code> as a type of internet connection on the
     *         device. Returns -1 in case of error or none of
     *         <code>ConnectivityManager.TYPE_*</code> is found.
     **/
public static int getDataConnectionType(Context ctx) {
    ConnectivityManager connectivityManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager != null && connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) != null) {
        if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected()) {
            return ConnectivityManager.TYPE_MOBILE;
        } else if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) {
            return ConnectivityManager.TYPE_WIFI;
        } else
            return -1;
    } else
        return -1;
}

71. 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;
}

72. Utilities#onWifi()

Project: Android-Remote
File: Utilities.java
/**
     * Is the device connceted to a wifi network?
     *
     * @return true if connected to a wifi network
     */
@SuppressWarnings("deprecation")
public static boolean onWifi() {
    ConnectivityManager connManager = (ConnectivityManager) App.getApp().getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean onWifi = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Network[] networks = connManager.getAllNetworks();
        NetworkInfo networkInfo;
        for (Network mNetwork : networks) {
            networkInfo = connManager.getNetworkInfo(mNetwork);
            if (networkInfo.getState().equals(NetworkInfo.State.CONNECTED) && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                onWifi = true;
                break;
            }
        }
    } else {
        //noinspection deprecation
        onWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
    }
    return onWifi;
}

73. 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());
}

74. 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;
    }
}

75. Network#printNetworkInfo()

Project: android-lite-http
File: Network.java
/**
	 * ??????????
	 * @param context
	 * @return boolean
	 */
public static boolean printNetworkInfo(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo in = connectivity.getActiveNetworkInfo();
        Log.i(TAG, "-------------$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$-------------");
        Log.i(TAG, "getActiveNetworkInfo: " + in);
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                // if (info[i].getType() == ConnectivityManager.TYPE_WIFI) {
                Log.i(TAG, "NetworkInfo[" + i + "]isAvailable : " + info[i].isAvailable());
                Log.i(TAG, "NetworkInfo[" + i + "]isConnected : " + info[i].isConnected());
                Log.i(TAG, "NetworkInfo[" + i + "]isConnectedOrConnecting : " + info[i].isConnectedOrConnecting());
                Log.i(TAG, "NetworkInfo[" + i + "]: " + info[i]);
            // }
            }
            Log.i(TAG, "\n");
        } else {
            Log.i(TAG, "getAllNetworkInfo is null");
        }
    }
    return false;
}

76. Network#printNetworkInfo()

Project: android-lite-http
File: Network.java
/**
	 * ??????????
	 * @param context
	 * @return boolean
	 */
public static boolean printNetworkInfo(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo in = connectivity.getActiveNetworkInfo();
        HttpLog.i(TAG, "-------------$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$-------------");
        HttpLog.i(TAG, "getActiveNetworkInfo: " + in);
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                // if (info[i].getType() == ConnectivityManager.TYPE_WIFI) {
                HttpLog.i(TAG, "NetworkInfo[" + i + "]isAvailable : " + info[i].isAvailable());
                HttpLog.i(TAG, "NetworkInfo[" + i + "]isConnected : " + info[i].isConnected());
                HttpLog.i(TAG, "NetworkInfo[" + i + "]isConnectedOrConnecting : " + info[i].isConnectedOrConnecting());
                HttpLog.i(TAG, "NetworkInfo[" + i + "]: " + info[i]);
            // }
            }
            HttpLog.i(TAG, "\n");
        } else {
            HttpLog.i(TAG, "getAllNetworkInfo is null");
        }
    }
    return false;
}

77. Network#printNetworkInfo()

Project: android-common
File: Network.java
/**
     * ??????????
     *
     * @return boolean
     */
public static boolean printNetworkInfo(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo in = connectivity.getActiveNetworkInfo();
        Log.i(TAG, "-------------$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$-------------");
        Log.i(TAG, "getActiveNetworkInfo: " + in);
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                // if (info[i].getType() == ConnectivityManager.TYPE_WIFI) {
                Log.i(TAG, "NetworkInfo[" + i + "]isAvailable : " + info[i].isAvailable());
                Log.i(TAG, "NetworkInfo[" + i + "]isConnected : " + info[i].isConnected());
                Log.i(TAG, "NetworkInfo[" + i + "]isConnectedOrConnecting : " + info[i].isConnectedOrConnecting());
                Log.i(TAG, "NetworkInfo[" + i + "]: " + info[i]);
            // }
            }
            Log.i(TAG, "\n");
        } else {
            Log.i(TAG, "getAllNetworkInfo is null");
        }
    }
    return false;
}

78. NetWorkHelper#isNetworkRoaming()

Project: android-app
File: NetWorkHelper.java
/**
	 * ?????????
	 */
public static boolean isNetworkRoaming(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        Log.w(LOG_TAG, "couldn't get connectivity manager");
    } else {
        NetworkInfo info = connectivity.getActiveNetworkInfo();
        if (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE) {
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            if (tm != null && tm.isNetworkRoaming()) {
                Log.d(LOG_TAG, "network is roaming");
                return true;
            } else {
                Log.d(LOG_TAG, "network is not roaming");
            }
        } else {
            Log.d(LOG_TAG, "not using mobile network");
        }
    }
    return false;
}

79. NetWorkHelper#checkNetState()

Project: android-app
File: NetWorkHelper.java
public static boolean checkNetState(Context context) {
    boolean netstate = false;
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    netstate = true;
                    break;
                }
            }
        }
    }
    return netstate;
}

80. NetWorkHelper#isNetworkAvailable()

Project: android-app
File: NetWorkHelper.java
/**
	 * ?????????
	 */
public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        Log.w(LOG_TAG, "couldn't get connectivity manager");
    } else {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                if (info[i].isAvailable()) {
                    Log.d(LOG_TAG, "network is available");
                    return true;
                }
            }
        }
    }
    Log.d(LOG_TAG, "network is not available");
    return false;
}

81. 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();
}

82. ConnectivityUtil#getNetworkInfo()

Project: MVPAndroidBootstrap
File: ConnectivityUtil.java
/**
     * Get the network info
     *
     * @return
     */
public static NetworkInfo getNetworkInfo(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getActiveNetworkInfo();
}

83. Game#checkDataConnection()

Project: moonlight-android
File: Game.java
private void checkDataConnection() {
    ConnectivityManager mgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (mgr.isActiveNetworkMetered()) {
        displayTransientMessage(getResources().getString(R.string.conn_metered));
    }
}

84. Systems#getActiveNetworkInfo()

Project: gpslogger
File: Systems.java
private static NetworkInfo getActiveNetworkInfo(Context context) {
    if (context == null) {
        return null;
    }
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm == null) {
        return null;
    }
    // note that this may return null if no network is currently active
    return cm.getActiveNetworkInfo();
}

85. Connectivity#getNetworkInfo()

Project: FaceSlim
File: Connectivity.java
/**
     * Get the network info
     * @param context app context
     * @return NetworkInfo
     */
public static NetworkInfo getNetworkInfo(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getActiveNetworkInfo();
}

86. Utils#getActiveNetworkInfo()

Project: external-resources
File: Utils.java
@Nullable
public static NetworkInfo getActiveNetworkInfo(Context context) {
    if (!hasNetworkStatePermission(context)) {
        Logger.w(ExternalResources.TAG, "To work perfectly, ACCESS_NETWORK_STATE permission is required.");
        return null;
    }
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
    return connectivityManager.getActiveNetworkInfo();
}

87. NetUtils#getNetworkInfo()

Project: Conquer
File: NetUtils.java
private static NetworkInfo getNetworkInfo(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getActiveNetworkInfo();
}

88. CommonUtils#getNetworkInfo()

Project: Conquer
File: CommonUtils.java
private static NetworkInfo getNetworkInfo(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getActiveNetworkInfo();
}

89. SystemLib#setDataConnectionEnabled()

Project: Cafe
File: SystemLib.java
/**
     * set mobile data enabled
     */
public void setDataConnectionEnabled() {
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    cm.setMobileDataEnabled(true);
}

90. SystemLib#setDataConnectionDisabled()

Project: Cafe
File: SystemLib.java
/**
     * set mobile data disabled
     */
public void setDataConnectionDisabled() {
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    cm.setMobileDataEnabled(false);
}

91. SystemLib#setBackgroundDataSetting()

Project: Cafe
File: SystemLib.java
/**
     * set background data
     * 
     * @param enabled
     */
public void setBackgroundDataSetting(boolean enabled) {
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    cm.setBackgroundDataSetting(enabled);
    try {
        // wait for setBackgroundDataSetting completed
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

92. SystemLib#getBackgroundDataState()

Project: Cafe
File: SystemLib.java
/**
     * get background data state
     * 
     * @return
     */
public boolean getBackgroundDataState() {
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getBackgroundDataSetting();
}

93. NetworkConnectivity#getNetworkInfo()

Project: browser-android
File: NetworkConnectivity.java
/**
	 * Get the network info
	 * @param context
	 * @return
	 */
public static NetworkInfo getNetworkInfo(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getActiveNetworkInfo();
}

94. SystemUtils#isNetworkConnectionAvailable()

Project: androidclient
File: SystemUtils.java
/** Checks for network availability. */
public static boolean isNetworkConnectionAvailable(Context context) {
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm.getBackgroundDataSetting()) {
        NetworkInfo info = cm.getActiveNetworkInfo();
        if (info != null && info.getState() == NetworkInfo.State.CONNECTED)
            return true;
    }
    return false;
}

95. XMPPService#getNetworkInfo()

Project: yaxim
File: XMPPService.java
private NetworkInfo getNetworkInfo() {
    Context ctx = getApplicationContext();
    ConnectivityManager connMgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    return connMgr.getActiveNetworkInfo();
}

96. NetworkUtils#getActiveNetworkInfo()

Project: WordPress-Android
File: NetworkUtils.java
/**
     * returns information on the active network connection
     */
private static NetworkInfo getActiveNetworkInfo(Context context) {
    if (context == null) {
        return null;
    }
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm == null) {
        return null;
    }
    // note that this may return null if no network is currently active
    return cm.getActiveNetworkInfo();
}

97. ConnectivityUtil#getNetworkInfo()

Project: RxAndroidBootstrap
File: ConnectivityUtil.java
/**
     * Get the network info
     *
     * @return
     */
public static NetworkInfo getNetworkInfo(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getActiveNetworkInfo();
}

98. Utils#ensureRouteToHost()

Project: qksms
File: Utils.java
/**
     * Ensures that the host MMSC is reachable
     *
     * @param context is the context of the activity or service
     * @param url     is the MMSC to check
     * @param proxy   is the proxy of the APN to check
     * @throws java.io.IOException when route cannot be established
     */
public static void ensureRouteToHost(Context context, String url, String proxy) throws IOException {
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    connMgr.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE_HIPRI, "enableMMS");
    if (LOCAL_LOGV)
        Log.v(TAG, "ensuring route to host");
    int inetAddr;
    if (proxy != null && !proxy.equals("")) {
        String proxyAddr = proxy;
        inetAddr = lookupHost(proxyAddr);
        if (inetAddr == -1) {
            throw new IOException("Cannot establish route for " + url + ": Unknown host");
        } else {
            if (!connMgr.requestRouteToHost(ConnectivityManager.TYPE_MOBILE_MMS, inetAddr)) {
                throw new IOException("Cannot establish route to proxy " + inetAddr);
            }
        }
    } else {
        Uri uri = Uri.parse(url);
        inetAddr = lookupHost(uri.getHost());
        if (inetAddr == -1) {
            throw new IOException("Cannot establish route for " + url + ": Unknown host");
        } else {
            if (!connMgr.requestRouteToHost(ConnectivityManager.TYPE_MOBILE_MMS, inetAddr)) {
                throw new IOException("Cannot establish route to " + inetAddr + " for " + url);
            }
        }
    }
}

99. NetworkUtils#isWifiConnected()

Project: popcorn-android-legacy
File: NetworkUtils.java
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     * is wifi connected
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/**
     * Get whether or not a wifi connection is currently connected.
     */
public static boolean isWifiConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager == null)
        return false;
    return connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
}

100. PlutusAndroid#isNetworkAvailable()

Project: PlutusAndroid
File: PlutusAndroid.java
public boolean isNetworkAvailable() {
    final ConnectivityManager connectivityManager = ((ConnectivityManager) getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE));
    return connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isConnected();
}