List of usage examples for android.net NetworkInfo getType
@Deprecated public int getType()
From source file:com.dmbstream.android.util.Util.java
public static boolean isNetworkConnected(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getActiveNetworkInfo(); boolean connected = networkInfo != null && networkInfo.isConnected(); boolean wifiConnected = connected && networkInfo.getType() == ConnectivityManager.TYPE_WIFI; boolean wifiRequired = isWifiRequiredForDownload(context); return connected && (!wifiRequired || wifiConnected); }
From source file:android_network.hetnet.vpn_service.Util.java
public static String getNetworkGeneration(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); return (ni != null && ni.getType() == ConnectivityManager.TYPE_MOBILE ? getNetworkGeneration(ni.getSubtype()) : null);//from w w w . j a va2s . co m }
From source file:android_network.hetnet.vpn_service.Util.java
public static boolean isWifiActive(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo()); return (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI); }
From source file:com.sxnyodot.uefqvmio207964.Util.java
static boolean m963j(Context context) { if (context == null) { return false; }/*from ww w .j a v a 2 s . c o m*/ try { NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")) .getActiveNetworkInfo(); if (activeNetworkInfo == null || !activeNetworkInfo.isConnected()) { return false; } int type = activeNetworkInfo.getType(); if (type == 1) { System.out.println("CONNECTED VIA WIFI"); return true; } if (type == 0) { switch (activeNetworkInfo.getSubtype()) { case DetectedActivity.IN_VEHICLE /*0*/: return false; case DetectedActivity.ON_BICYCLE /*1*/: return false; case DetectedActivity.ON_FOOT /*2*/: return false; case DetectedActivity.STILL /*3*/: return true; case DetectedActivity.UNKNOWN /*4*/: return false; case DetectedActivity.TILTING /*5*/: return true; case GamesClient.STATUS_NETWORK_ERROR_OPERATION_FAILED /*6*/: return true; case GamesClient.STATUS_LICENSE_CHECK_FAILED /*7*/: return false; case NETWORK_TYPE_HSDPA /*8*/: return true; case NETWORK_TYPE_HSUPA /*9*/: return true; case NETWORK_TYPE_HSPA /*10*/: return true; case NETWORK_TYPE_IDEN /*11*/: return false; case NETWORK_TYPE_EVDO_B /*12*/: return true; case NETWORK_TYPE_LTE /*13*/: return true; case NETWORK_TYPE_EHRPD /*14*/: return true; case NETWORK_TYPE_HSPAP /*15*/: return true; default: return false; } } return false; } catch (Exception e) { e.printStackTrace(); } }
From source file:com.just.agentweb.AgentWebUtils.java
public static boolean checkWifi(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { return false; }//from w ww .j a v a 2 s .co m @SuppressLint("MissingPermission") NetworkInfo info = connectivity.getActiveNetworkInfo(); return info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI; }
From source file:Main.java
public boolean isNetworkRoaming(Context mCm) { ConnectivityManager connectivity = (ConnectivityManager) mCm.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { return false; }// w w w.j a v a2s . co m NetworkInfo info = connectivity.getActiveNetworkInfo(); boolean isMobile = (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE); TelephonyManager mTm = (TelephonyManager) mCm.getSystemService(Context.TELEPHONY_SERVICE); boolean isRoaming = isMobile && mTm.isNetworkRoaming(); return isRoaming; }
From source file:com.just.agentweb.AgentWebUtils.java
public static int checkNetworkType(Context context) { int netType = 0; //?/*from ww w .j a v a 2 s .c om*/ ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); //?NetworkInfo @SuppressLint("MissingPermission") NetworkInfo networkInfo = manager.getActiveNetworkInfo(); if (networkInfo == null) { return netType; } switch (networkInfo.getType()) { case ConnectivityManager.TYPE_WIFI: case ConnectivityManager.TYPE_WIMAX: case ConnectivityManager.TYPE_ETHERNET: return 1; case ConnectivityManager.TYPE_MOBILE: switch (networkInfo.getSubtype()) { case TelephonyManager.NETWORK_TYPE_LTE: // 4G case TelephonyManager.NETWORK_TYPE_HSPAP: case TelephonyManager.NETWORK_TYPE_EHRPD: return 2; case TelephonyManager.NETWORK_TYPE_UMTS: // 3G case TelephonyManager.NETWORK_TYPE_CDMA: case TelephonyManager.NETWORK_TYPE_EVDO_0: case TelephonyManager.NETWORK_TYPE_EVDO_A: case TelephonyManager.NETWORK_TYPE_EVDO_B: return 3; case TelephonyManager.NETWORK_TYPE_GPRS: // 2G case TelephonyManager.NETWORK_TYPE_EDGE: return 4; default: return netType; } default: return netType; } }
From source file:com.roamprocess1.roaming4world.syncadapter.SyncAdapter.java
public static int getConnectivityStatus(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (null != activeNetwork) { if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) return SipHome.TYPE_WIFI; if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) return SipHome.TYPE_MOBILE; }// w w w .j a v a 2s . c o m return SipHome.TYPE_NOT_CONNECTED; }
From source file:com.example.android.networkbasic.MainActivity.java
/** * Check whether the device is connected, and if so, whether the connection * is wifi or mobile (it could be something else). *//*w w w . ja va 2 s . c o m*/ private void checkNetworkConnection() { ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeInfo = connMgr.getActiveNetworkInfo(); if (activeInfo != null && activeInfo.isConnected()) { wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI; mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE; if (wifiConnected) { Log.i(TAG, getString(R.string.wifi_connection)); } else if (mobileConnected) { Log.i(TAG, getString(R.string.mobile_connection)); } } else { Log.i(TAG, getString(R.string.no_wifi_or_mobile)); } }