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
/** * To check whether current network is wifi. * * @param context context/*from w ww. j a v a2s .co m*/ * @return true if network if wifi, otherwise return false */ protected static boolean isWifi(Context context) { if (context == null) { return false; } ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); return info != null && (info.getType() == ConnectivityManager.TYPE_WIFI); }
From source file:Main.java
public static boolean checkNetWork(final Context context) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = cm.getActiveNetworkInfo(); if ((netInfo != null) && netInfo.isConnectedOrConnecting()) { return true; }/*from w ww . j a v a 2 s.c om*/ return false; }
From source file:Main.java
public static boolean isOnline(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting() && cm.getActiveNetworkInfo().isAvailable() && cm.getActiveNetworkInfo().isConnected()) { return true; }/*from w w w.j a v a 2 s . c o m*/ return false; }
From source file:Main.java
public static boolean checkNetWork(Context context) { boolean newWorkOK = false; ConnectivityManager connectManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectManager.getActiveNetworkInfo() != null) { newWorkOK = true;// w w w . jav a2 s.c o m } return newWorkOK; }
From source file:Main.java
/** * Returns <tt>true</tt> if the Connections is available. Else returns <tt>false</tt>. * * @return/* ww w . j a va2 s . c o m*/ */ public static boolean isConnectedOnline(Context myContext) { ConnectivityManager cmObj = (ConnectivityManager) myContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfoObj = cmObj.getActiveNetworkInfo(); return networkInfoObj != null && networkInfoObj.isConnected(); }
From source file:Main.java
public static boolean isNetConnected(Context context) { boolean connected = false; ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getActiveNetworkInfo(); if (networkInfo != null) { connected = networkInfo.isConnected(); }// www. j a v a 2 s. c o m return connected; }
From source file:Main.java
public static boolean isWifiConnected(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); return info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI; }
From source file:Main.java
private static boolean isNetworkConnected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni == null) // There are no active networks. return false; else/*from w w w. j a v a 2 s .co m*/ return true; }
From source file:Main.java
public static boolean isNetWorkAvilable(final Context context) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = cm.getActiveNetworkInfo(); return networkInfo == null || !networkInfo.isAvailable(); }
From source file:Main.java
public static boolean isConnectedViaWiFi(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return cm != null && cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI && cm.getActiveNetworkInfo().getState() == State.CONNECTED; }