List of usage examples for android.net ConnectivityManager getActiveNetworkInfo
@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@Nullable
public NetworkInfo getActiveNetworkInfo()
From source file:Main.java
public static boolean isChargeFreeNetworkAvailable(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = manager.getActiveNetworkInfo(); return (activeNetworkInfo != null && activeNetworkInfo.isConnected() && (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI || activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIMAX || activeNetworkInfo.getType() == ConnectivityManager.TYPE_ETHERNET)); }
From source file:Main.java
/** * Determine the current networking is WIFI * // w ww . j av a 2 s. c o m * @param context * @return */ public static boolean CurrentNoteworkTypeIsWIFI(Context context) { ConnectivityManager connectionManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); return connectionManager.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI; }
From source file:Main.java
final public static boolean isNetworkConnected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni != null) { return cm.getActiveNetworkInfo().isConnected(); }/*from www.j av a 2 s . c om*/ return false; }
From source file:Main.java
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 {//from ww w . ja v a2s .co m return 2; } }
From source file:Main.java
/** * Determine the current networking is WIFI * /*from w ww.j a va2 s .c o m*/ * @param context * @return */ public static boolean currentNoteworkTypeIsWIFI(Context context) { ConnectivityManager connectionManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); return connectionManager.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI; }
From source file:Main.java
protected static int getMoblieNetType(Context context) { ConnectivityManager connectMgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connectMgr.getActiveNetworkInfo(); return info.getSubtype(); }
From source file:Main.java
public static final boolean connected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info != null && info.isConnectedOrConnecting()) { return true; }/* w ww . j a va2 s . com*/ return false; }
From source file:Main.java
/** * is network avaliable//from ww w.j a v a2 s.c om * * @param context * @return */ public static boolean isNetworkAvaliable(Context context) { ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { return true; } else { return false; } }
From source file:Main.java
private static boolean isNetworkAvailable(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); return info != null; }
From source file:Main.java
public static synchronized boolean isNetworkAvailable(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null) { return netInfo.isConnected(); } else {//from w w w .ja va2s .c o m return false; } }