Java Code Examples for android.net.NetworkInfo#State

The following examples show how to use android.net.NetworkInfo#State . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetUtils.java    From easyweather with MIT License 6 votes vote down vote up
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;
}
 
Example 2
Source File: NetUtil.java    From AppServiceRestFul with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 获取网络状态
 *
 * @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;
}
 
Example 3
Source File: StatsTraffic.java    From Cangol-appcore with Apache License 2.0 6 votes vote down vote up
private void endCalcAppTraffic() {
    final String date = TimeUtils.getCurrentDate();
    NetworkInfo.State wifiState = null;
    NetworkInfo.State mobileState = null;
    final ConnectivityManager cm = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);

    @SuppressLint("MissingPermission") final NetworkInfo networkInfoWifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (networkInfoWifi != null) {
        wifiState = networkInfoWifi.getState();
    }
    @SuppressLint("MissingPermission") final NetworkInfo networkInfoMobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (networkInfoMobile != null) {
        mobileState = networkInfoMobile.getState();
    }
    if (wifiState != null && NetworkInfo.State.CONNECTED == wifiState) {
        // 无线网络连接
        calcAppTraffic(date, true);
    } else if (mobileState != null && NetworkInfo.State.CONNECTED == mobileState) {
        // 手机网络连接
        calcAppTraffic(date, false);
    }
}
 
Example 4
Source File: NetUtil.java    From AppServiceRestFul with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 获取网络状态
 *
 * @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;
}
 
Example 5
Source File: RouteService.java    From Mobike with Apache License 2.0 6 votes vote down vote up
@Override
        public void onReceive(Context context, Intent intent) {
            NetworkInfo.State wifiState = null;
            NetworkInfo.State mobileState = null;
            ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            wifiState = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
            mobileState = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
            if (wifiState != null && mobileState != null
                    && NetworkInfo.State.CONNECTED != wifiState
                    && NetworkInfo.State.CONNECTED == mobileState) {
//                Toast.makeText(context, context.getString(R.string.net_mobile), Toast.LENGTH_SHORT).show();
                // 手机网络连接成功
            } else if (wifiState != null && mobileState != null
                    && NetworkInfo.State.CONNECTED != wifiState
                    && NetworkInfo.State.CONNECTED != mobileState) {
//                Toast.makeText(context, context.getString(R.string.net_none), Toast.LENGTH_SHORT).show();

                // 手机没有任何的网络
            } else if (wifiState != null && NetworkInfo.State.CONNECTED == wifiState) {
                // 无线网络连接成功
//                Toast.makeText(context, context.getString(R.string.net_wifi), Toast.LENGTH_SHORT).show();

            }
        }
 
Example 6
Source File: AbstractNetworkReceiver.java    From chat21-android-sdk with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (null != intent) {
        NetworkInfo.State wifiState = null;
        NetworkInfo.State mobileState = null;
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        wifiState = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
        mobileState = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
        if (wifiState != null && mobileState != null
                && NetworkInfo.State.CONNECTED != wifiState
                && NetworkInfo.State.CONNECTED == mobileState) {
            // phone network connect success
            mobileNetwork();
        } else if (wifiState != null && mobileState != null
                && NetworkInfo.State.CONNECTED != wifiState
                && NetworkInfo.State.CONNECTED != mobileState) {
            // no network
            noNetwork();
        } else if (wifiState != null && NetworkInfo.State.CONNECTED == wifiState) {
            // wify connect success
            WIFINetwork();
        }
    }
}
 
Example 7
Source File: ApplicationLoader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isConnectedOrConnectingToWiFi() {
    try {
        ensureCurrentNetworkGet(false);
        if (currentNetworkInfo != null && (currentNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI || currentNetworkInfo.getType() == ConnectivityManager.TYPE_ETHERNET)) {
            NetworkInfo.State state = currentNetworkInfo.getState();
            if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING || state == NetworkInfo.State.SUSPENDED) {
                return true;
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    return false;
}
 
Example 8
Source File: NetworkStateReceiver.java    From ForPDA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "onReceive " + intent);
    if (!(intent.getAction() != null && intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION))) {
        return;
    }
    NetworkInfo.State newConnectionType = getCurrentConnectionType();
    if (newConnectionType == mConnectionType) return;

    mConnectionType = newConnectionType;
    Log.d(TAG, "Network connectivity changed, type is: " + mConnectionType);

    Client.get(context).notifyNetworkObservers(mConnectionType == NetworkInfo.State.CONNECTED);
}
 
Example 9
Source File: NetWorkUtils.java    From Simpler with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前网络的状态
 *
 * @param context 上下文
 * @return 当前网络的状态。具体类型可参照NetworkInfo.State.CONNECTED、NetworkInfo.State.CONNECTED.DISCONNECTED等字段。当前没有网络连接时返回null
 */
public static NetworkInfo.State getCurrentNetworkState(Context context) {
    NetworkInfo networkInfo
            = ((ConnectivityManager) context.getSystemService(
            Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
    return networkInfo != null ? networkInfo.getState() : null;
}
 
Example 10
Source File: WifiUtils.java    From FileTransfer with GNU General Public License v3.0 5 votes vote down vote up
public static NetworkInfo.State getWifiConnectState(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context
            .CONNECTIVITY_SERVICE);
    if (manager == null) {
        return NetworkInfo.State.DISCONNECTED;
    }
    NetworkInfo mWiFiNetworkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (mWiFiNetworkInfo != null) {
        return mWiFiNetworkInfo.getState();
    }
    return NetworkInfo.State.DISCONNECTED;
}
 
Example 11
Source File: WiFiModule.java    From WIFIADB with Apache License 2.0 5 votes vote down vote up
public boolean isReady(){
    boolean enable = isEnable();

    if(enable){
        final NetworkInfo.State state = mConnectivityManager
                .getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();

        enable = (state == NetworkInfo.State.CONNECTED);
    }

    return enable;
}
 
Example 12
Source File: NetworkUtils.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * Return whether using ethernet.
 * <p>Must hold
 * {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />}</p>
 *
 * @return {@code true}: yes<br>{@code false}: no
 */
@RequiresPermission(ACCESS_NETWORK_STATE)
private static boolean isEthernet() {
    final ConnectivityManager cm =
            (ConnectivityManager) Utils.getApp().getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm == null) return false;
    final NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
    if (info == null) return false;
    NetworkInfo.State state = info.getState();
    if (null == state) return false;
    return state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING;
}
 
Example 13
Source File: ApplicationLoader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isConnectedOrConnectingToWiFi() {
    try {
        ensureCurrentNetworkGet(false);
        if (currentNetworkInfo != null && (currentNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI || currentNetworkInfo.getType() == ConnectivityManager.TYPE_ETHERNET)) {
            NetworkInfo.State state = currentNetworkInfo.getState();
            if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING || state == NetworkInfo.State.SUSPENDED) {
                return true;
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    return false;
}
 
Example 14
Source File: NetWorkUtils.java    From GankGirl with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 获取当前网络的状态
 *
 * @param context 上下文
 * @return 当前网络的状态。具体类型可参照NetworkInfo.State.CONNECTED、NetworkInfo.State.CONNECTED.DISCONNECTED等字段。当前没有网络连接时返回null
 */
public static NetworkInfo.State getCurrentNetworkState(Context context) {
    NetworkInfo networkInfo
            = ((ConnectivityManager) context.getSystemService(
            Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
    return networkInfo != null ? networkInfo.getState() : null;
}
 
Example 15
Source File: NetworkStatusChangeReceiver.java    From QuickerAndroid with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public void onReceive(Context context, Intent intent) {

        // ref:https://blog.csdn.net/qq_20785431/article/details/51520459
        // 监听wifi的连接状态即是否连上了一个有效无线路由
        if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
            Parcelable parcelableExtra = intent
                    .getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
            if (null != parcelableExtra) {
                // 获取联网状态的NetWorkInfo对象
                NetworkInfo networkInfo = (NetworkInfo) parcelableExtra;
                //获取的State对象则代表着连接成功与否等状态
                NetworkInfo.State state = networkInfo.getState();
                //判断网络是否已经连接
                boolean isConnected = state == NetworkInfo.State.CONNECTED;
                Log.e("TAG", "wifi连接:" + isConnected);
                EventBus.getDefault().post(new WifiStatusChangeEvent(isConnected));
            }
        }


//        if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
//            ConnectivityManager manager = (ConnectivityManager) context
//                    .getSystemService(Context.CONNECTIVITY_SERVICE);
//            NetworkInfo activeNetwork = manager.getActiveNetworkInfo();
//
//
//            if (activeNetwork != null) { // connected to the internet
//                if (activeNetwork.isConnected()) {
//                    if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
//                        Log.d(TAG,"当前WiFi连接可用 ");
//                    } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
//                        Log.d(TAG,"当前移动网络连接可用 ");
//                    }
//                    //发送广播通知服务重新启动
//                    Bus.post(new ConnectClosedEvent(Contants.CONNECT_CLOSE_TYPE));
//                } else {
//                    LogUtil.w("当前没有网络连接,请确保你已经打开网络 ");
//                    //无网络连接,通知socket,取消每三秒重连接
//                    Bus.post(new ConnectCloseAllEvent(true));
//                }
//            } else {   // not connected to the internet
//                LogUtil.w("当前没有网络连接,请确保你已经打开网络 ");
//                //无网络连接,通知socket,取消每三秒重连接
//                Bus.post(new ConnectCloseAllEvent(true));
//            }
//        }
    }
 
Example 16
Source File: NetworkChangeEvent.java    From slidingdebugmenu with Apache License 2.0 4 votes vote down vote up
public NetworkChangeEvent(NetworkInfo.State wifiState, NetworkInfo.State mobileState, BluetoothState bluetoothState) {
    this.wifiState = wifiState;
    this.mobileState = mobileState;
    this.bluetoothState = bluetoothState;
}
 
Example 17
Source File: StatsTraffic.java    From Cangol-appcore with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Log.v("getAction=" + intent.getAction());
    if (BOOT_ACTION.equals(intent.getAction())) {
        // 开机启动
        resetAppTraffic();
    } else if (NETWORK_ACTION.equals(intent.getAction())) {
        NetworkInfo.State wifiState = null;
        NetworkInfo.State mobileState = null;
        final ConnectivityManager cm = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);

        @SuppressLint("MissingPermission") final NetworkInfo networkInfoWifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (networkInfoWifi != null) {
            wifiState = networkInfoWifi.getState();
        }
        @SuppressLint("MissingPermission") final NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (networkInfo != null) {
            mobileState = networkInfo.getState();
        }

        if (wifiState != null && NetworkInfo.State.CONNECTED == wifiState) {
            // 无线网络连接
            Log.d("wifi connected calcTraffic");
            calcAppTraffic(TimeUtils.getCurrentDate(), true);
        } else if (wifiState != null && NetworkInfo.State.DISCONNECTED == wifiState) {
            // 无线网络中断
            Log.d("wifi disconnect calcTraffic");
            calcAppTraffic(TimeUtils.getCurrentDate(), true);
        } else if (mobileState != null && NetworkInfo.State.CONNECTED == mobileState) {
            // 手机网络连接
            Log.d("mobile connected calcTraffic");
            calcAppTraffic(TimeUtils.getCurrentDate(), false);
        } else if (mobileState != null && NetworkInfo.State.DISCONNECTED == mobileState) {
            // 手机网络中断
            Log.d("mobile disconnect calcTraffic");
            calcAppTraffic(TimeUtils.getCurrentDate(), false);
        } else {
            //
        }

    } else {
        //day end
        Log.d("day end calcTraffic");
        endCalcAppTraffic();
    }
}
 
Example 18
Source File: NetworkUtils.java    From Trojan with Apache License 2.0 4 votes vote down vote up
public static int getNetworkType(Context context) {
    if (null == context) {
        return NETWORK_NONE;
    }
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (null == connectivityManager) {
        return NETWORK_NONE;
    }

    final NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    if (null == activeNetInfo || !activeNetInfo.isAvailable()) {
        return NETWORK_NONE;
    } else if (activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return NETWORK_WIFI;
    } else if (activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        final NetworkInfo.State state = activeNetInfo.getState();
        final String subTypeName = activeNetInfo.getSubtypeName();
        if (null != state) {
            switch (activeNetInfo.getSubtype()) {
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    return NETWORK_2G;
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_UMTS:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_B:
                case TelephonyManager.NETWORK_TYPE_EHRPD:
                case TelephonyManager.NETWORK_TYPE_HSPAP:
                    return NETWORK_3G;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return NETWORK_4G;
                default:
                    if (subTypeName.equalsIgnoreCase("TD-SCDMA")
                            || subTypeName.equalsIgnoreCase("WCDMA")
                            || subTypeName.equalsIgnoreCase("CDMA2000")) {
                        return NETWORK_3G;
                    } else {
                        return NETWORK_UNKNOWN_MOBILE;
                    }
            }
        }
    }
    return NETWORK_NONE;
}
 
Example 19
Source File: NetworkConnectChangedReceiver.java    From AndroidDemo with MIT License 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {// 这个监听wifi的打开与关闭,与wifi的连接无关

    if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) {
        int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
        Log.e(TAG0, "WIFI状态:" + wifiState);
        switch (wifiState) {
            case WifiManager.WIFI_STATE_DISABLED:
                //APP.getInstance().setEnablaWifi(false);
                Log.e(TAG0,"WIFI_STATE_DISABLED" );
                break;
            case WifiManager.WIFI_STATE_DISABLING:
                Log.e(TAG0,"WIFI_STATE_DISABLING" );
                break;
            case WifiManager.WIFI_STATE_ENABLING:
                Log.e(TAG0,"WIFI_STATE_ENABLING" );
                break;
            case WifiManager.WIFI_STATE_ENABLED:
                //APP.getInstance().setEnablaWifi(true);
                Log.e(TAG0,"WIFI_STATE_ENABLED");
                break;
            case WifiManager.WIFI_STATE_UNKNOWN:
                Log.e(TAG0,"WIFI_STATE_UNKNOWN" );
                break;
            default:
                break;
        }
    }
    // 这个监听wifi的连接状态即是否连上了一个有效无线路由,当上边广播的状态是WifiManager
    // .WIFI_STATE_DISABLING,和WIFI_STATE_DISABLED的时候,根本不会接到这个广播。
    // 在上边广播接到广播是WifiManager.WIFI_STATE_ENABLED状态的同时也会接到这个广播,
    // 当然刚打开wifi肯定还没有连接到有效的无线
    if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
        Parcelable parcelableExtra = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        if (null != parcelableExtra) {
            NetworkInfo networkInfo = (NetworkInfo) parcelableExtra;
            NetworkInfo.State state = networkInfo.getState();
            boolean isConnected = state == NetworkInfo.State.CONNECTED;// 当然,这边可以更精确的确定状态
            Log.e(TAG1, "WIFI连接状态:" + isConnected);
            if (isConnected) {
                //APP.getInstance().setWifi(true);
            } else {
               // APP.getInstance().setWifi(false);
            }
        }
    }
    // 这个监听网络连接的设置,包括wifi和移动数据的打开和关闭。.
    // 最好用的还是这个监听。wifi如果打开,关闭,以及连接上可用的连接都会接到监听。
    // 这个广播的最大弊端是比上边两个广播的反应要慢,如果只是要监听wifi,觉得还是用上边两个配合比较合适。
    if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
        ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        Log.i(TAG2, "CONNECTIVITY_ACTION");
        string = "\n您的手机当前网络状态是:\n\n";
        NetworkInfo activeNetwork = manager.getActiveNetworkInfo();
        if (activeNetwork != null) { // connected to the internet
            if (activeNetwork.isConnected()) {
                if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
                    // connected to wifi
                    string += "当前WiFi连接可用 ";
                } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
                    // connected to the mobile provider's data plan
                    string += "当前移动网络连接可用 ";
                }
            } else {
                string += "当前没有网络连接,请确保你已经打开网络 ";
            }

            string +=   "\n类型名:"        + activeNetwork.getTypeName()+
                        "\n子类型名:"       + activeNetwork.getSubtypeName()+
                        "\n状态:"           + activeNetwork.getState()+
                        "\n详细状态:"       + activeNetwork.getDetailedState().name()+
                        "\n额外状态:"       + activeNetwork.getExtraInfo()+
                        "\n类型:"           + activeNetwork.getType();
        } else {   // not connected to the internet
            string += "当前没有网络连接,请确保你已经打开网络 ";
        }
        Log.e("String:",string);
        brInteraction.setText(string);

    }

}
 
Example 20
Source File: NetworkConnectChangedReceiver.java    From apollo-DuerOS with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    // Monitor wifi status, have nothing to do with wifi connection
    if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) {
        int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
        LogUtil.d(TAG, "wifiState:" + wifiState);
        switch (wifiState) {
            case WifiManager.WIFI_STATE_DISABLED:
                break;
            case WifiManager.WIFI_STATE_DISABLING:
                break;
            default:
                break;
        }
    }
    // Monitor the connection status of WiFi, that is whether or not there is an effective wireless routing
    if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
        Parcelable parcelableExtra = intent
                .getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        if (null != parcelableExtra) {
            // Get the network status of the NetWorkInfo object
            NetworkInfo networkInfo = (NetworkInfo) parcelableExtra;
            // The State object is the state of connection success or not
            NetworkInfo.State state = networkInfo.getState();
            // Determine whether or not the network has been connected
            boolean isConnected = state == NetworkInfo.State.CONNECTED;
            LogUtil.d(TAG, "isConnected:" + isConnected);
        }
    }
    // To monitor the network connection, including wifi and mobile data opening and closing,
    // as well as connection available on the connection had been listening
    if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
        // Get the NetworkInfo object of the network state
        NetworkInfo info = intent
                .getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
        if (info != null) {
            // If the current network connection is successful and the network connection is available
            if (NetworkInfo.State.CONNECTED == info.getState() && info.isAvailable()) {
                if (info.getType() == ConnectivityManager.TYPE_WIFI
                        || info.getType() == ConnectivityManager.TYPE_MOBILE) {
                    LogUtil.i(TAG, getConnectionType(info.getType()) + " connected");
                    // transform to the following module
                    if (mOnNetworkChangeListener != null) {
                        LogUtil.i(TAG, "mOnLocationListener is set");
                        mOnNetworkChangeListener.onNetworkChange();
                    }
                }
            } else {
                LogUtil.i(TAG, getConnectionType(info.getType()) + " disconnected");
                if (mOnNetworkChangeListener != null) {
                    LogUtil.i(TAG, "onShowCompass is set");
                    mOnNetworkChangeListener.onShowCompass();
                }
            }
        }

    }
}