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 String getCurrentNetwordByName(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); String name = null;//from w ww. j a va 2 s. co m if (networkInfo != null) { name = networkInfo.getTypeName(); } return name; }
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() == false) { return false; }/*from w w w . j av a2 s. c om*/ return true; }
From source file:Main.java
public static boolean isWifiConnected(Context context) { ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (mgr == null) return false; NetworkInfo info = mgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (info == null) return false; NetworkInfo.State state = info.getState(); return state == NetworkInfo.State.CONNECTED || state == NetworkInfo.State.CONNECTING; }
From source file:Main.java
public static boolean isNetworkConnected(Context context) { ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo net = conn.getActiveNetworkInfo(); if (net != null && net.isConnected()) { return true; } else {// w w w . j a v a 2 s .c o m return false; } }
From source file:Main.java
public static int getNetWorkType(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork == null) return -1; if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) { return 1; } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) { return 0; } else {//from ww w.ja v a2 s.c om return 2; } }
From source file:Main.java
public static String getApn(final Context context) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS).getExtraInfo(); }
From source file:Main.java
public static boolean isNetworkConnectedByWifi(Context context) { NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)) .getNetworkInfo(ConnectivityManager.TYPE_WIFI); return networkInfo != null && networkInfo.isConnected(); }
From source file:Main.java
public static boolean IsNetworkConnectionAvailable(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); return (info != null && info.isConnected()); }
From source file:Main.java
public static boolean isMobileDataEnable(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); boolean isMobileDataEnable = false; isMobileDataEnable = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) .isConnectedOrConnecting();// www. j a v a2 s.c o m return isMobileDataEnable; }
From source file:Main.java
public static boolean checkNetWork(final Context context) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = cm.getActiveNetworkInfo(); if ((netInfo != null) && netInfo.isConnectedOrConnecting()) { return true; }/*from ww w . ja v a2s . c o m*/ return false; }