Back to project page android-json-http.
The source code is released under:
Apache License
If you think the Android project android-json-http listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.open.jsonhttp.util; //w w w. j a va2 s . c o m import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import com.example.App; /** * ??????? * * @author yinghui.hong */ public class NetwrokUtil { /** * ??? */ public static final int STATE_CONNECT_NONE = 0; /** * WIFI?? */ public static final int STATE_CONNECT_WIFI = 1; /** * ???? 2G/3G */ public static final int STATE_CONNECT_MOBILE = 2; /** * ?????????????? * * @param context * @return ??? STATE_CONNECT_NONE????? STATE_CONNECT_WIFI?WIFI??, * STATE_CONNECT_MOBILE????? 2G/3G */ public static int getNetConnectState(Context context) { final ConnectivityManager cm = (ConnectivityManager) App.context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm .getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo != null && networkInfo.isConnected()) { return STATE_CONNECT_WIFI; } networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (networkInfo != null && networkInfo.isConnected()) { return STATE_CONNECT_MOBILE; } return STATE_CONNECT_NONE; } /** * ?????????? * * @param context * @return */ public static boolean isConnected() { final ConnectivityManager cm = (ConnectivityManager) App.context .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) { return false; } return true; } }