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
private static boolean isNetworkConnected(Context context, int typeMobile) { boolean ret = false; if (!isNetConnected(context)) { return ret; }// w w w. j a v a 2 s. co m ConnectivityManager connectManger = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectManger.getNetworkInfo(typeMobile); if (networkInfo == null) { return ret; } return ret; }
From source file:Main.java
/** * Returns <tt>true</tt> if the Connections is available. Else returns <tt>false</tt>. * * @return//from ww w . jav a2 s .c om */ 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
/** * Checked the network connect status.//from ww w .ja v a 2 s .co m */ public static boolean isNetworkConnected(Context context) { if (context == null) { return false; } ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); return (networkInfo != null && networkInfo.isConnected()); }
From source file:Main.java
/** * Check to see if the network is available. * @return true if there is access to the internet, false otherwise. *///from w w w.jav a2 s .c o m public static boolean isNetworkAvailable(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); boolean isAvailable = false; if (info != null && info.isConnected()) { isAvailable = true; } Log.v("TheNetUtil", "isNetworkAvailable(). net is " + isAvailable); return isAvailable; }
From source file:Main.java
public static String getCurrentSsid(Context context) { String ssid = null;//w ww . j a v a 2 s. c om ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo.isConnected()) { final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); final WifiInfo connectionInfo = wifiManager.getConnectionInfo(); if (connectionInfo != null && connectionInfo.getSSID() != null && !connectionInfo.getSSID().equals("")) { ssid = connectionInfo.getSSID(); } } return ssid == null ? ssid : ssid.replace("\"", ""); }
From source file:Main.java
/** * Checks if there is any sort of Internet connection * @param context/* w w w . j a v a 2s . c o m*/ * the context in which to check Internet state * @return true if connected to Internet, false if not */ public static boolean isOnline(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo() == null) return false; return cm.getActiveNetworkInfo().isConnected(); }
From source file:Main.java
public static boolean checkConnection(Context context) throws NoConnectionPendingException { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { return false; } else {/*from ww w .ja v a2 s . co m*/ NetworkInfo info = connectivity.getActiveNetworkInfo(); if (info != null) { if (info.getState() == NetworkInfo.State.CONNECTED) { return true; } } } return false; }
From source file:Main.java
/** * <pre>/*from w w w . j a va 2 s . com*/ * Determine whether network is currently connected. * </pre> */ public static boolean isNetworkConnected() { ConnectivityManager conMan = (ConnectivityManager) getCurrentContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = conMan.getActiveNetworkInfo(); return activeNetwork != null && activeNetwork.isConnected(); }
From source file:Main.java
/** * Check mobile data is enable or not.//from www. jav a2s.co m * @param context * @return */ public static boolean isMobileDataEnable(Context context) { boolean mobileDataEnabled = false; // Assume disabled ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); try { Class cmClass = Class.forName(cm.getClass().getName()); Method method = cmClass.getDeclaredMethod("getMobileDataEnabled"); method.setAccessible(true); // Make the method callable // get the setting for "mobile data" mobileDataEnabled = (Boolean) method.invoke(cm); } catch (Exception e) { // Some problem accessible private API e.printStackTrace(); } return mobileDataEnabled; }
From source file:Main.java
public static int getNetworkState(Context context) { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); // Wifi/* www.ja v a 2 s. c o m*/ NetworkInfo.State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING) { return NETWORN_WIFI; } // 3G state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); if (state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING) { return NETWORN_MOBILE; } return NETWORN_NONE; }