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 isWifiOr3G(Context ctx) { ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info == null) return false; int netType = info.getType(); int netSubtype = info.getSubtype(); if (netType == ConnectivityManager.TYPE_WIFI) { return info.isConnected(); } else if (netType == ConnectivityManager.TYPE_MOBILE && netSubtype == TelephonyManager.NETWORK_TYPE_UMTS) { return info.isConnected(); } else {//from w w w . j ava2s . c o m return false; } }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { Log.v(TAG, " ConnectivityManager: " + " " + "networkInfo.isConnected()"); return true; } else {// ww w . j a v a2 s .c o m Log.v(TAG, " ConnectivityManager: " + " " + "networkInfo = null"); return false; } }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { return false; } else {// w w w . jav a 2s.c o m NetworkInfo info = connectivity.getActiveNetworkInfo(); if (info == null) { return false; } else { if (info.isAvailable()) { return true; } } } return false; }
From source file:Main.java
public static boolean checkNet(Context context) { try {//from www . ja va 2 s. c o m ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo info = connectivity.getActiveNetworkInfo(); if (info != null && info.isConnected()) { if (info.getState() == NetworkInfo.State.CONNECTED) { return true; } } } } catch (Exception e) { return false; } return false; }
From source file:Main.java
public static int isHightBandwidthConnection(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); return isConnectionFast(info.getType(), info.getSubtype()); }
From source file:Main.java
public static boolean isNetworkConnected(@NonNull Context context) { ConnectivityManager cm = (ConnectivityManager) context.getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); return activeNetwork != null && activeNetwork.isConnectedOrConnecting(); }
From source file:Main.java
public static boolean isNetConnect(@NonNull Context context) { ConnectivityManager service = (ConnectivityManager) context.getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = service.getActiveNetworkInfo(); return info != null && info.isAvailable(); }
From source file:Main.java
public static int getNetworkType(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); State mobileState = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); State wifiState = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if (wifiState == State.CONNECTED || wifiState == State.CONNECTING) { return 1; } else if (mobileState == State.CONNECTED || mobileState == State.CONNECTING) { return 2; } else {//from w w w . j ava2 s . c o m return 0; } }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { boolean netstate = false; ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { netstate = true;//from www. jav a2 s . c o m break; } } } } return netstate; }
From source file:Main.java
public static boolean isWifiOnline(Context context) { ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if (wifi == NetworkInfo.State.CONNECTED) return true; else/*from w ww . j av a2 s . c o m*/ return false; }