Here you can find the source of getNetworkState(Context context)
public static int getNetworkState(Context context)
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.NetworkInfo.State; public class Main { public final static int NONE = 0; public final static int WIFI = 1; public final static int MOBILE = 2; public static int getNetworkState(Context context) { if (null != context) { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); State state;//from w ww. j av a2s. com NetworkInfo networkInfo; if (null != connManager) { //Wifi???? networkInfo = connManager .getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (null != networkInfo) { state = networkInfo.getState(); if (state == State.CONNECTED || state == State.CONNECTING) { return WIFI; } } //3G???? networkInfo = connManager .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (null != networkInfo) { state = networkInfo.getState(); if (state == State.CONNECTED || state == State.CONNECTING) { return MOBILE; } } } } return NONE; } }