List of usage examples for android.content Context CONNECTIVITY_SERVICE
String CONNECTIVITY_SERVICE
To view the source code for android.content Context CONNECTIVITY_SERVICE.
Click Source Link
From source file:Main.java
public static boolean checkNetworkAvailable(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { return false; } else {// w w w . ja v a 2 s . co m NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { NetworkInfo netWorkInfo = info[i]; if (netWorkInfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; } else if (netWorkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { return true; } } } } } return false; }
From source file:Main.java
public static boolean isConnectionToMobile(Context applicationContext) { ConnectivityManager connectivityManager = (ConnectivityManager) applicationContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (networkInfo != null && networkInfo.isConnectedOrConnecting()) { return true; }/*from www .jav a 2 s .c om*/ return false; }
From source file:Main.java
public static boolean isNetWorkConnected(Context context) { boolean result; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); result = netInfo != null && netInfo.isConnected(); return result; }
From source file:Main.java
public static boolean isOpenNetwork(Context context) { if (null == context) { return false; }//from w w w . ja v a 2 s. c o m ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connManager.getActiveNetworkInfo() != null) { return connManager.getActiveNetworkInfo().isAvailable(); } return false; }
From source file:Main.java
public static boolean isNetworkAvaliable(Context context) { ConnectivityManager manager = (ConnectivityManager) (context .getSystemService(Context.CONNECTIVITY_SERVICE)); NetworkInfo networkinfo = manager.getActiveNetworkInfo(); return !(networkinfo == null || !networkinfo.isAvailable()); }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); if (manager == null) { return false; }// w w w. ja va2 s . c om NetworkInfo networkinfo = manager.getActiveNetworkInfo(); if (networkinfo == null || !networkinfo.isAvailable()) { return false; } return true; }
From source file:Main.java
public static boolean isNetworkAvailable(Activity activity) { ConnectivityManager connectivityManager = (ConnectivityManager) activity .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.isConnected(); }
From source file:Main.java
public static boolean isNetWorkConnected(Context context) { if (context == null) return false; ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); if (info != null) return info.isAvailable(); return false; }
From source file:Main.java
public static NetworkInfo getCurrentActiveNetwork(Context mContext) { try {// www. java2 s . c om ConnectivityManager connectivity = (ConnectivityManager) mContext .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { return connectivity.getActiveNetworkInfo(); } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static boolean isNetworkAvailable(Context c) { ConnectivityManager connectivityManager = (ConnectivityManager) c .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.isConnected(); }