List of usage examples for android.net NetworkInfo getTypeName
@Deprecated
public String getTypeName()
From source file:Main.java
public static boolean isNetworkAvailable(Context ctx) { ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { String name = ni.getTypeName(); if (name.equalsIgnoreCase("ETH")) if (ni.isConnected()) return true; if (name.equalsIgnoreCase("WIFI")) if (ni.isConnected()) return true; if (name.equalsIgnoreCase("MOBILE")) if (ni.isConnected()) return true; }//from ww w .jav a2 s.c o m return false; }
From source file:Main.java
/** * @param context/*from w ww . j a va 2 s . c o m*/ * @return */ public static String getNetWorkName(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm == null) return "MOBILE"; NetworkInfo info = cm.getActiveNetworkInfo(); if (info != null) return info.getTypeName(); else return "MOBILE"; }
From source file:Main.java
public static boolean isWifi(Context mContext) { ConnectivityManager connectivityManager = (ConnectivityManager) mContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetInfo != null && activeNetInfo.getTypeName().equals("WIFI")) { return true; }// w ww . j a v a2 s .c o m return false; }
From source file:Main.java
@SuppressLint("DefaultLocale") public static boolean isWifi(Context context) { try {//from www . j a v a 2 s . c om ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo nInfo = cm.getActiveNetworkInfo(); if (nInfo != null) { return nInfo.getTypeName().toUpperCase().equals("WIFI"); } } } catch (Exception e) { } return false; }
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 w w . j av a2 s . c o m*/ if (networkInfo != null) { name = networkInfo.getTypeName(); } return name; }
From source file:Main.java
public static boolean isWifiNetwrokType(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connectivityManager.getActiveNetworkInfo(); if (info != null && info.isAvailable()) { if (info.getTypeName().equalsIgnoreCase("wifi")) { return true; }/* w w w. ja v a 2 s .c o m*/ } return false; }
From source file:Main.java
public static boolean isWifiConnected(final Context context) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = cm.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isConnected() && networkInfo.getTypeName().equalsIgnoreCase("WIFI"); }
From source file:Main.java
public static String getNetworkType(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (manager == null) return "NO CONNECTIVITY"; NetworkInfo netInfo = manager.getActiveNetworkInfo(); if (netInfo == null) return "NO ACTIVE NETWORK"; return netInfo.getTypeName().toLowerCase(); }
From source file:Main.java
/** * This method checks if the Network available on the device or not. * //from www. j a v a2s . c o m * @param context * @return true if network available, false otherwise */ public static Boolean isNetworkAvailable(Context context) { boolean connected = false; final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) { connected = true; } else if (netInfo != null && netInfo.isConnected() && cm.getActiveNetworkInfo().isAvailable()) { connected = true; } else if (netInfo != null && netInfo.isConnected()) { try { URL url = new URL("http://www.google.com"); HttpURLConnection urlc = (HttpURLConnection) url.openConnection(); urlc.setConnectTimeout(3000); urlc.connect(); if (urlc.getResponseCode() == 200) { connected = true; } } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else if (cm != null) { final NetworkInfo[] netInfoAll = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfoAll) { System.out.println("get network type :::" + ni.getTypeName()); if ((ni.getTypeName().equalsIgnoreCase("WIFI") || ni.getTypeName().equalsIgnoreCase("MOBILE")) && ni.isConnected() && ni.isAvailable()) { connected = true; if (connected) { break; } } } } return connected; }
From source file:Main.java
public static NetworkInfo getActiveNetworkInfo(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo != null) { Log.i(TAG, "N/W Type: " + activeNetworkInfo.getTypeName()); }/*w w w . j a v a 2 s . c o m*/ return activeNetworkInfo; }