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 isWifi(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); return (activeNetInfo != null) && (activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI); }
From source file:Main.java
public static boolean isNetworkAvailable(Context context) { ConnectivityManager mConnMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWifi = mConnMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mMobile = mConnMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); boolean flag = false; if ((mWifi != null) && ((mWifi.isAvailable()) || (mMobile.isAvailable()))) { if ((mWifi.isConnected()) || (mMobile.isConnected())) { flag = true;//from ww w . j a va 2s . co m } } return flag; }
From source file:Main.java
public static boolean isNetworkAvaliable(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (manager != null) { NetworkInfo[] info = manager.getAllNetworkInfo(); for (int i = 0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; }/*from w w w. ja v a 2s .c o m*/ } } return false; }
From source file:Main.java
public static boolean isConnection(Context applicationContext) { ConnectivityManager connectivityManager = (ConnectivityManager) applicationContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnectedOrConnecting()) { return true; }// w ww .j a v a 2 s . com return false; }
From source file:Main.java
public static boolean check3GNetworkInfo(Context context) { try {/* ww w.j a v a2s. c o m*/ ConnectivityManager conMan = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); //mobile 3G Data Network State mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); return (mobile == State.CONNECTED || mobile == State.CONNECTING); } catch (Exception e) { return false; } }
From source file:Main.java
public static boolean checkWifyNetworkInfo(Context context) { try {//from ww w . j a va 2 s. co m ConnectivityManager conMan = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); //wifi State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); return (wifi == State.CONNECTED || wifi == State.CONNECTING); } catch (Exception e) { return true; } }
From source file:Main.java
public static boolean isNetworkAvailable(Context ctx) { if (ctx == null) { return false; }// w ww . java 2s.com 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 isConnectedToWired(Context context) { ConnectivityManager connec = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); //ConnectivityManager.TYPE_ETHERNET == 9 , but only from API 13 NetworkInfo ethernet = connec.getNetworkInfo(9); if (ethernet != null && ethernet.isConnected()) { return true; } else {/*from w w w .ja v a 2 s .c o m*/ return false; } }
From source file:Main.java
public static boolean checkWifiNetwork(Context context) { boolean has = false; ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connectivity.getActiveNetworkInfo(); int netType = info.getType(); int netSubtype = info.getSubtype(); if (netType == ConnectivityManager.TYPE_WIFI) { has = info.isConnected();//from w w w. j ava 2s .c om } return has; }
From source file:Main.java
public static boolean isConnectionToWifi(Context applicationContext) { ConnectivityManager connectivityManager = (ConnectivityManager) applicationContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo != null && networkInfo.isConnectedOrConnecting()) { return true; }//from w ww.jav a2 s . com return false; }