List of usage examples for android.net NetworkInfo getSubtype
@Deprecated public int getSubtype()
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 ww. j a va2 s. c o m }
From source file:com.sxnyodot.uefqvmio207964.Util.java
static boolean m963j(Context context) { if (context == null) { return false; }/* w w w . j a v a 2 s . c om*/ 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 int checkNetworkType(Context context) { int netType = 0; //?// www . jav 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.android.profilerapp.network.NetworkFragment.java
private Thread getStatisticThread() { return new Thread(new Runnable() { private Statistics statistics; private long[] myStartBytes; private long[] myBytes; private void initialize() { statistics = new Statistics(); myStartBytes = getTrafficBytes(Integer.toString(myUid)); }//from w ww . j ava2s. co m @Override public void run() { initialize(); while (!Thread.currentThread().isInterrupted()) { myBytes = getTrafficBytes(Integer.toString(myUid)); statistics.sendBytesFromFile = myBytes[0] - myStartBytes[0]; statistics.receiveBytesFromFile = myBytes[1] - myStartBytes[1]; // Gets the bytes from API too, because API read is later than file read, API results may be a little larger. myBytes[0] = TrafficStats.getUidTxBytes(myUid) - myStartBytes[0]; myBytes[1] = TrafficStats.getUidRxBytes(myUid) - myStartBytes[1]; if (statistics.sendBytesFromFile > myBytes[0] || statistics.receiveBytesFromFile > myBytes[1]) { Log.d(TAG, String.format( "Bytes reported not in sync. TrafficStats: %1$d, %2$d, getTrafficBytes: %3$d, %4$d", myBytes[0], myBytes[1], statistics.sendBytesFromFile, statistics.receiveBytesFromFile)); } NetworkInfo networkInfo = myConnectivityManager.getActiveNetworkInfo(); statistics.networkName = networkInfo != null && networkInfo.getSubtype() != TelephonyManager.NETWORK_TYPE_UNKNOWN ? networkInfo.getSubtypeName() : networkInfo.getTypeName(); statistics.radioStatus = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? myConnectivityManager.isDefaultNetworkActive() ? "Radio high power" : "Radio not high power" : "Radio status unknown"; statistics.openConnectionCount = getConnectionCount(Integer.toString(myUid)); postStatistics(statistics); try { Thread.currentThread().sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } } }); }
From source file:android_network.hetnet.vpn_service.Util.java
public static String getNetworkInfo(Context context) { StringBuilder sb = new StringBuilder(); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ani = cm.getActiveNetworkInfo(); List<NetworkInfo> listNI = new ArrayList<>(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) listNI.addAll(Arrays.asList(cm.getAllNetworkInfo())); else//from w w w . jav a 2s . co m for (Network network : cm.getAllNetworks()) { NetworkInfo ni = cm.getNetworkInfo(network); if (ni != null) listNI.add(ni); } for (NetworkInfo ni : listNI) { sb.append(ni.getTypeName()).append('/').append(ni.getSubtypeName()).append(' ') .append(ni.getDetailedState()) .append(TextUtils.isEmpty(ni.getExtraInfo()) ? "" : " " + ni.getExtraInfo()) .append(ni.getType() == ConnectivityManager.TYPE_MOBILE ? " " + Util.getNetworkGeneration(ni.getSubtype()) : "") .append(ni.isRoaming() ? " R" : "") .append(ani != null && ni.getType() == ani.getType() && ni.getSubtype() == ani.getSubtype() ? " *" : "") .append("\r\n"); } try { Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); if (nis != null) while (nis.hasMoreElements()) { NetworkInterface ni = nis.nextElement(); if (ni != null && !ni.isLoopback()) { List<InterfaceAddress> ias = ni.getInterfaceAddresses(); if (ias != null) for (InterfaceAddress ia : ias) sb.append(ni.getName()).append(' ').append(ia.getAddress().getHostAddress()) .append('/').append(ia.getNetworkPrefixLength()).append(' ') .append(ni.getMTU()).append(' ').append(ni.isUp() ? '^' : 'v') .append("\r\n"); } } } catch (Throwable ex) { sb.append(ex.toString()).append("\r\n"); } if (sb.length() > 2) sb.setLength(sb.length() - 2); return sb.toString(); }
From source file:com.master.metehan.filtereagle.Util.java
public static String getNetworkInfo(Context context) { StringBuilder sb = new StringBuilder(); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ani = cm.getActiveNetworkInfo(); List<NetworkInfo> listNI = new ArrayList<>(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) listNI.addAll(Arrays.asList(cm.getAllNetworkInfo())); else//from w ww. j a v a 2s. c om for (Network network : cm.getAllNetworks()) { NetworkInfo ni = cm.getNetworkInfo(network); if (ni != null) listNI.add(ni); } for (NetworkInfo ni : listNI) { sb.append(ni.getTypeName()).append('/').append(ni.getSubtypeName()).append(' ') .append(ni.getDetailedState()) .append(TextUtils.isEmpty(ni.getExtraInfo()) ? "" : " " + ni.getExtraInfo()) .append(ni.getType() == ConnectivityManager.TYPE_MOBILE ? " " + Util.getNetworkGeneration(ni.getSubtype()) : "") .append(ni.isRoaming() ? " R" : "") .append(ani != null && ni.getType() == ani.getType() && ni.getSubtype() == ani.getSubtype() ? " *" : "") .append("\r\n"); } try { Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); if (nis != null) { sb.append("\r\n"); while (nis.hasMoreElements()) { NetworkInterface ni = nis.nextElement(); if (ni != null) { List<InterfaceAddress> ias = ni.getInterfaceAddresses(); if (ias != null) for (InterfaceAddress ia : ias) sb.append(ni.getName()).append(' ').append(ia.getAddress().getHostAddress()) .append('/').append(ia.getNetworkPrefixLength()).append(' ') .append(ni.getMTU()).append("\r\n"); } } } } catch (Throwable ex) { sb.append(ex.toString()).append("\r\n"); } if (sb.length() > 2) sb.setLength(sb.length() - 2); return sb.toString(); }
From source file:com.error.hunter.ListenService.java
private StringBuffer getNetworkInfo() { StringBuffer info = new StringBuffer(); StringBuffer backUpInfo = new StringBuffer(); final ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifi.isConnected()) { info.append("\nWiFi network state: CONNECTED"); } else {//from ww w. ja va2 s . c o m info.append("\nWiFi network state: NOT CONNECTED"); } backUpInfo = new StringBuffer(info); try { if (!mobile.isConnected()) { switch (mobile.getSubtype()) { case TelephonyManager.NETWORK_TYPE_GPRS: info.append("\nMobile network state: CONNECTED (GPRS)"); break; case TelephonyManager.NETWORK_TYPE_EDGE: info.append("\nMobile network state: CONNECTED (EDGE)"); break; case TelephonyManager.NETWORK_TYPE_CDMA: info.append("\nMobile network state: CONNECTED (CDMA)"); break; case TelephonyManager.NETWORK_TYPE_HSPA: info.append("\nMobile network state: CONNECTED (HSPA)"); break; case TelephonyManager.NETWORK_TYPE_HSPAP: info.append("\nMobile network state: CONNECTED (HSPA+)"); break; case TelephonyManager.NETWORK_TYPE_LTE: info.append("\nMobile network state: CONNECTED (LTE)"); break; case TelephonyManager.NETWORK_TYPE_UMTS: info.append("\nMobile network state: CONNECTED (UMTS)"); break; } } else { info.append("\nMobile network state: NOT CONNECTED"); } } catch (Exception e) { e.printStackTrace(); return backUpInfo; } return info; }
From source file:com.zhongsou.souyue.activity.SplashActivity.java
protected boolean parseNetStatus(NetworkInfo ni) { if (ni == null) throw new RuntimeException("ni can not be null"); if (highSpeed.contains(ni.getSubtype()) || ni.getType() == ConnectivityManager.TYPE_WIFI) return true; return false; }
From source file:fr.inria.ucn.collectors.NetworkStateCollector.java
/** * // w ww. java2 s. co m * @param c * @param ts * @param change */ @SuppressWarnings("deprecation") @SuppressLint({ "DefaultLocale", "NewApi" }) public void run(Context c, long ts, boolean change) { try { // current active interface (wifi or mobile) and config ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); JSONObject data = new JSONObject(); data.put("on_network_state_change", change); // this collection run was triggered by network change data.put("is_connected", (ni != null && ni.isConnectedOrConnecting())); data.put("is_roaming", tm.isNetworkRoaming()); // airplane mode ? if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.JELLY_BEAN) { data.put("is_airplane_mode", (Settings.System.getInt(c.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0)); } else { data.put("is_airplane_mode", (Settings.Global.getInt(c.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0)); } if (ni != null) { JSONObject active = new JSONObject(); active.put("type", ni.getType()); active.put("subtype", ni.getSubtype()); active.put("type_name", ni.getTypeName()); active.put("subtype_name", ni.getSubtypeName()); active.put("state", ni.getState().toString()); active.put("detailed_state", ni.getDetailedState().toString()); active.put("is_wifi", (ni.getType() == ConnectivityManager.TYPE_WIFI)); data.put("active_network", active); if (ni.getType() == ConnectivityManager.TYPE_WIFI) { data.put("wifi_network", getWifi(c)); } } // mobile network details data.put("mobile_network", getMobile(tm)); // kernel network statistics data.put("netstat", getNetstat()); // interfaces config Map<String, JSONObject> stats = networkStats(); data.put("ifconfig", getIfconfig(stats)); // double check interfaces data.put("ip_addr_show", getIpAddr(stats)); Helpers.sendResultObj(c, "network_state", ts, data); } catch (JSONException jex) { Log.w(Constants.LOGTAG, "failed to create json object", jex); } }
From source file:com.ferdi2005.secondgram.voip.VoIPService.java
private void updateNetworkType() { ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); lastNetInfo = info;//from w w w .ja va2 s.c om int type = VoIPController.NET_TYPE_UNKNOWN; if (info != null) { switch (info.getType()) { case ConnectivityManager.TYPE_MOBILE: switch (info.getSubtype()) { case TelephonyManager.NETWORK_TYPE_GPRS: type = VoIPController.NET_TYPE_GPRS; break; case TelephonyManager.NETWORK_TYPE_EDGE: case TelephonyManager.NETWORK_TYPE_1xRTT: type = VoIPController.NET_TYPE_EDGE; break; case TelephonyManager.NETWORK_TYPE_UMTS: case TelephonyManager.NETWORK_TYPE_EVDO_0: type = VoIPController.NET_TYPE_3G; break; case TelephonyManager.NETWORK_TYPE_HSDPA: case TelephonyManager.NETWORK_TYPE_HSPA: case TelephonyManager.NETWORK_TYPE_HSPAP: case TelephonyManager.NETWORK_TYPE_HSUPA: case TelephonyManager.NETWORK_TYPE_EVDO_A: case TelephonyManager.NETWORK_TYPE_EVDO_B: type = VoIPController.NET_TYPE_HSPA; break; case TelephonyManager.NETWORK_TYPE_LTE: type = VoIPController.NET_TYPE_LTE; break; default: type = VoIPController.NET_TYPE_OTHER_MOBILE; break; } break; case ConnectivityManager.TYPE_WIFI: type = VoIPController.NET_TYPE_WIFI; break; case ConnectivityManager.TYPE_ETHERNET: type = VoIPController.NET_TYPE_ETHERNET; break; } } if (controller != null) { controller.setNetworkType(type); } }