List of usage examples for android.net NetworkInfo getType
@Deprecated public int getType()
From source file:com.frame.network.utils.NetworkUtil.java
/** * ?//w ww. j av a 2 s. co m * @param context * @return */ public static int getNetworkType(Context context) { if (context == null) { return -1; } ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (info == null) { return -1; } return info.getType(); }
From source file:com.lemi.mario.download.utils.Proxy.java
static final private boolean isNetworkWifi(Context context) { if (context == null) { return false; }//from w ww .j a v a 2 s . co m final ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { final NetworkInfo info = connectivity.getActiveNetworkInfo(); if (info != null && info.getType() == ConnectivityManager.TYPE_WIFI) { return true; } } return false; }
From source file:siarhei.luskanau.gps.tracker.free.utils.Utils.java
public static boolean isWifiNetworkType(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager != null) { NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { return networkInfo.getType() == ConnectivityManager.TYPE_WIFI; }/*from w w w. ja v a 2 s . c o m*/ } return false; }
From source file:Main.java
public static int hasActiveNetworkInfo(Context context) { int state = 0; // Assume disabled final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mActiveNetworkInfo = cm.getActiveNetworkInfo(); if (mActiveNetworkInfo != null) { String typeName = mActiveNetworkInfo.getTypeName().toLowerCase(); boolean isConnected = mActiveNetworkInfo.isConnectedOrConnecting(); int type = mActiveNetworkInfo.getType(); if ((isNetworkTypeMobile(type)) && (typeName.contains("mobile")) && isConnected) state = 2;// w ww. j av a 2s . c o m else if ((!isNetworkTypeMobile(type)) && (!typeName.contains("mobile")) && isConnected) state = 1; } return state; }
From source file:com.github.czy1121.update.app.utils.UpdateUtil.java
public static boolean checkWifi(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { return false; }//from w ww . j a v a2 s .c o m NetworkInfo info = connectivity.getActiveNetworkInfo(); return info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI; }
From source file:Main.java
public static int getCurrentNetType(Context context) { int result = NETTYPE_NONE; NetworkInfo localNetworkInfo = getCurrentActiveNetworkInfo(context); if (localNetworkInfo == null) { return result; }// w ww .j av a2 s . c o m if (localNetworkInfo.getState() == NetworkInfo.State.CONNECTED) { if (localNetworkInfo.getType() == 1) { result = NETTYPE_WIFI; } else if (localNetworkInfo.getType() == 0) { String subTypeName = localNetworkInfo.getSubtypeName().toUpperCase(Locale.getDefault()); if (subTypeName.indexOf("GPRS") > 1) { result = NETTYPE_MOBILE_GPRS; } else if (subTypeName.indexOf("EDGE") > 1) { result = NETTYPE_MOBILE_EDGE; } else { result = NETTYPE_MOBILE_3G; } } else { result = NETTYPE_UNKNOW; } } else if (localNetworkInfo.getState() == NetworkInfo.State.CONNECTING) { result = NETTYPE_UNKNOW; System.out.println("connecting " + localNetworkInfo.getType()); } return result; }
From source file:Main.java
static public boolean isDisconnectedIntent(Intent intent) { boolean res = false; NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); if (networkInfo != null) { NetworkInfo.State state = networkInfo.getState(); res = (state.equals(NetworkInfo.State.DISCONNECTING) || state.equals(NetworkInfo.State.DISCONNECTED)) && (networkInfo.getType() == ConnectivityManager.TYPE_WIFI); } else {/*from www .jav a 2 s . com*/ int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN); if (wifiState == WifiManager.WIFI_STATE_DISABLED || wifiState == WifiManager.WIFI_STATE_DISABLING) { res = true; } } return res; }
From source file:com.lee.sdk.utils.NetUtils.java
/** * wifi??//from w w w .ja v a2 s.c o m * * @param context context * @return wifi? true */ public static boolean isWifiNetworkConnected(Context context) { NetworkInfo networkInfo = getActiveNetworkInfo(context); // return networkInfo != null && networkInfo.isConnected(); boolean flag = networkInfo != null && networkInfo.isAvailable() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI; if (DEBUG) { Log.d(TAG, "isWifiNetworkConnected, rtn: " + flag); } return flag; }
From source file:com.vinexs.tool.NetworkManager.java
public static boolean isWifiNetwork(Context context) { NetworkInfo info = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)) .getActiveNetworkInfo();/*from ww w. ja va2 s . co m*/ return info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI; }
From source file:com.nextgis.firereporter.HttpGetter.java
static boolean IsNetworkAvailible(Context c) { ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info == null /*|| !cm.getBackgroundDataSetting()*/) return false; int netType = info.getType(); //int netSubtype = info.getSubtype(); if (netType == ConnectivityManager.TYPE_WIFI) { return info.isConnected(); } else if (netType == ConnectivityManager.TYPE_MOBILE && /*netSubtype == TelephonyManager.NETWORK_TYPE_UMTS &&*/ !tm.isNetworkRoaming()) { return info.isConnected(); } else {//from w w w. j a va2 s. c o m return false; } }