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 isNetworkAvailable(Context context) { ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] info = mgr.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; }/*w w w. ja v a2 s.com*/ } } return false; }
From source file:Main.java
public static boolean isConnectingToInternet(Context ctx) { ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo[] info = cm.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; }//from w w w . ja v a 2 s . c o m } } } return false; }
From source file:Main.java
private static boolean isMOBILEConnection(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (networkInfo != null) { return networkInfo.isConnected(); }/* w w w. ja v a2 s.c o m*/ return false; }
From source file:Main.java
public static boolean getWifiState(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); State wifistate = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if (wifistate != State.CONNECTED) { return false; }/*ww w .ja v a 2 s .c o m*/ State mobileState = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); boolean ret = State.CONNECTED != mobileState; return ret; }
From source file:Main.java
public static boolean isNetworkConnected(Context context) { ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeInfo = connMgr.getActiveNetworkInfo(); if (activeInfo != null) { return activeInfo.isConnected(); }/*from w w w . jav a2s . c o m*/ return false; }
From source file:Main.java
private static boolean isConnectionAvailable(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 . java 2 s .com*/ return false; }
From source file:Main.java
public static boolean isNetworkAvaliable(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { return true; }/* w w w . j a v a 2s .c om*/ return false; }
From source file:Main.java
public static boolean isConnected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (null == cm) { return false; }/* ww w .j av a 2 s . co m*/ NetworkInfo info = cm.getActiveNetworkInfo(); if (null != info && info.isConnected()) { if (info.getState() == NetworkInfo.State.CONNECTED) { return true; } } return false; }
From source file:Main.java
public static boolean getMobileState(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); State wifistate = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if (wifistate != State.CONNECTED) { return false; }//from w ww.j a va 2 s . com State mobileState = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); boolean ret = State.CONNECTED == mobileState; return ret; }
From source file:Main.java
public static boolean isNetworkValidate(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo() != null) { return cm.getActiveNetworkInfo().isAvailable(); }/* w ww.j ava2 s . c om*/ return false; }