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 isOnline(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); //should check null because in air plan mode it will be null return (netInfo != null && netInfo.isConnected()); }
From source file:Main.java
public static boolean isConnected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); return activeNetwork != null && activeNetwork.isConnectedOrConnecting(); }
From source file:Main.java
/** * @param context//from ww w . j a v a 2s . co m * @return */ public static final boolean isNetworkAvailable(final Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); return netInfo != null && netInfo.isConnected(); }
From source file:Main.java
public static boolean isOnline(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Activity.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); return info != null && info.isConnected(); }
From source file:Main.java
public static boolean isWifiConnected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); return networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI; }
From source file:Main.java
public static boolean is3gConnected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); return networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE; }
From source file:Main.java
public static boolean isOnline(Context ctx) { ConnectivityManager connMgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); return (networkInfo != null && networkInfo.isConnected()); }
From source file:Main.java
public static boolean isNetworkOnline(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) { return true; }//from w w w . j ava2 s .c o m return false; }
From source file:Main.java
/** * Checks network availability/*from ww w .j ava2s.c o m*/ * * @param context * @return */ public static boolean isNetworkAvailable(Context context) { Log.v(TAG, "isNetworkAvailable called."); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo() == null) { Log.d(TAG, "no active network info found."); return false; } Log.v(TAG, "active network info found."); return cm.getActiveNetworkInfo().isConnectedOrConnecting(); }
From source file:Main.java
public static boolean isNetworkConnected(Context context) { ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo net = conn.getActiveNetworkInfo(); if (net != null && net.isConnected()) { return true; } else {/* www . j a va 2s.co m*/ return false; } }