List of usage examples for android.net ConnectivityManager TYPE_ETHERNET
int TYPE_ETHERNET
To view the source code for android.net ConnectivityManager TYPE_ETHERNET.
Click Source Link
From source file:edu.mit.mobile.android.locast.data.CastMedia.java
/** * Attempts to guess if the video player should show a high quality version of the video or a * lower bitrate version./*from w ww. ja v a 2 s.c om*/ * * @return true if it seems as though playing high-quality would be expensive or wouldn't work */ public static boolean shouldShowLowQuality(Context context) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final boolean metered = ConnectivityManagerCompat.isActiveNetworkMetered(cm); final NetworkInfo net = cm.getActiveNetworkInfo(); if (metered || net == null || net.isRoaming()) { return true; } // this is because these devices tend to not be able to be powerful enough to show the full // res video if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { return true; } final int type = net.getType(); switch (type) { // generally these are fast and cheap/free case ConnectivityManager.TYPE_WIFI: case ConnectivityManager.TYPE_ETHERNET: case ConnectivityManager.TYPE_WIMAX: return false; default: return true; } }
From source file:org.gateshipone.odyssey.artworkdatabase.BulkDownloadService.java
/** * Checks the current network state if an artwork download is allowed. * * @param context The current context to resolve the networkinfo * @return true if a download is allowed else false *//* ww w. ja v a 2 s . c o m*/ private boolean isDownloadAllowed(final Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (networkInfo == null) { return false; } else { boolean isWifi = cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI || cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_ETHERNET; return !(mWifiOnly && !isWifi); } }
From source file:org.deviceconnect.android.manager.core.util.DConnectUtil.java
/** * Gets the ip address./*w ww. j a v a2s . c o m*/ * * @param context Context of application * @return Returns ip address */ public static String getIPAddress(final Context context) { Context appContext = context.getApplicationContext(); WifiManager wifiManager = (WifiManager) appContext.getSystemService(Context.WIFI_SERVICE); ConnectivityManager cManager = (ConnectivityManager) appContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo network = cManager.getActiveNetworkInfo(); String en0Ip = null; if (network != null) { switch (network.getType()) { case ConnectivityManager.TYPE_ETHERNET: try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr .hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (inetAddress instanceof Inet4Address && !inetAddress.getHostAddress().equals("127.0.0.1")) { en0Ip = inetAddress.getHostAddress(); break; } } } } catch (SocketException e) { Log.e("DConnectUtil", "Get Ethernet IP Error", e); } } } if (en0Ip != null) { return en0Ip; } else { int ipAddress = wifiManager.getConnectionInfo().getIpAddress(); return String.format(Locale.getDefault(), "%d.%d.%d.%d", (ipAddress & 0xff), (ipAddress >> 8 & 0xff), (ipAddress >> 16 & 0xff), (ipAddress >> 24 & 0xff)); } }
From source file:syncthing.android.service.ServiceSettings.java
static boolean isWifiOrEthernet(int type) { return isWifi(type) || type == ConnectivityManager.TYPE_ETHERNET; }
From source file:com.miz.functions.MizLib.java
/** * Determines if the device is currently connected to a WiFi or Ethernet network * @param c - Context of the application * @return True if connected to a network, else false *//*from w w w. j av a2 s .c o m*/ public static boolean isWifiConnected(Context c) { if (c != null) { boolean disableEthernetWiFiCheck = PreferenceManager.getDefaultSharedPreferences(c) .getBoolean(DISABLE_ETHERNET_WIFI_CHECK, false); if (disableEthernetWiFiCheck) return isOnline(c); ConnectivityManager connManager = (ConnectivityManager) c .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] connections = connManager.getAllNetworkInfo(); int count = connections.length; for (int i = 0; i < count; i++) if (connections[i] != null && connections[i].getType() == ConnectivityManager.TYPE_WIFI && connections[i].isConnectedOrConnecting() || connections[i] != null && connections[i].getType() == ConnectivityManager.TYPE_ETHERNET && connections[i].isConnectedOrConnecting()) return true; } return false; }
From source file:org.openhab.habdroid.ui.OpenHABWidgetListActivity.java
/** * This is called when activity is created. Initializes the state, performs network * state based selection for app initialization and starts the widget list *//*from ww w.j a v a2 s.com*/ @Override public void onCreate(Bundle savedInstanceState) { Log.d("OpenHABWidgetListActivity", "onCreate"); // Set default values, false means do it one time during the very first launch PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Set non-persistant HABDroid version preference to current version from application package try { PreferenceManager.getDefaultSharedPreferences(this).edit().putString("default_openhab_appversion", getPackageManager().getPackageInfo(getPackageName(), 0).versionName).commit(); } catch (NameNotFoundException e1) { if (e1 != null) Log.d(TAG, e1.getMessage()); } // Set the theme to one from preferences Util.setActivityTheme(this); // Fetch openHAB service type name from strings.xml openHABServiceType = getString(R.string.openhab_service_type); // Enable progress ring bar requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); requestWindowFeature(Window.FEATURE_PROGRESS); setProgressBarIndeterminateVisibility(true); // Initialize crittercism reporting JSONObject crittercismConfig = new JSONObject(); try { crittercismConfig.put("shouldCollectLogcat", true); } catch (JSONException e) { if (e.getMessage() != null) Log.e(TAG, e.getMessage()); else Log.e(TAG, "Crittercism JSON exception"); } Crittercism.init(getApplicationContext(), "5117659f59e1bd4ba9000004", crittercismConfig); // Initialize activity view super.onCreate(savedInstanceState); setContentView(R.layout.openhabwidgetlist); // Disable screen timeout if set in preferences SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); if (settings.getBoolean("default_openhab_screentimeroff", false)) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } // Check if we got all needed permissions PackageManager pm = getPackageManager(); if (!(pm.checkPermission(permission.CHANGE_WIFI_MULTICAST_STATE, getPackageName()) == PackageManager.PERMISSION_GRANTED)) { showAlertDialog(getString(R.string.erorr_no_wifi_mcast_permission)); serviceDiscoveryEnabled = false; } if (!(pm.checkPermission(permission.ACCESS_WIFI_STATE, getPackageName()) == PackageManager.PERMISSION_GRANTED)) { showAlertDialog(getString(R.string.erorr_no_wifi_state_permission)); serviceDiscoveryEnabled = false; } // Get username/password from preferences openHABUsername = settings.getString("default_openhab_username", null); openHABPassword = settings.getString("default_openhab_password", null); // Create new data source and adapter and set it to list view openHABWidgetDataSource = new OpenHABWidgetDataSource(); openHABWidgetAdapter = new OpenHABWidgetAdapter(OpenHABWidgetListActivity.this, R.layout.openhabwidgetlist_genericitem, widgetList); getListView().setAdapter(openHABWidgetAdapter); // Set adapter parameters openHABWidgetAdapter.setOpenHABUsername(openHABUsername); openHABWidgetAdapter.setOpenHABPassword(openHABPassword); // Enable app logo as home button this.getActionBar().setHomeButtonEnabled(true); // Check if we have openHAB page url in saved instance state? if (savedInstanceState != null) { displayPageUrl = savedInstanceState.getString("displayPageUrl"); openHABBaseUrl = savedInstanceState.getString("openHABBaseUrl"); sitemapRootUrl = savedInstanceState.getString("sitemapRootUrl"); openHABWidgetAdapter.setOpenHABBaseUrl(openHABBaseUrl); } // Check if this is a launch from myself (drill down navigation) if (getIntent() != null) { if (getIntent().getAction() != null) { if (getIntent().getAction().equals("org.openhab.habdroid.ui.OpwnHABWidgetListActivity")) { displayPageUrl = getIntent().getExtras().getString("displayPageUrl"); openHABBaseUrl = getIntent().getExtras().getString("openHABBaseUrl"); sitemapRootUrl = getIntent().getExtras().getString("sitemapRootUrl"); this.setTitle(getIntent().getExtras().getString("pageTitle")); openHABWidgetAdapter.setOpenHABBaseUrl(openHABBaseUrl); } } } // If yes, then just go to it (means restore activity from it's saved state) if (displayPageUrl.length() > 0) { Log.d(TAG, "displayPageUrl = " + displayPageUrl); showPage(displayPageUrl, false); // If not means it is a clean start } else { if (getIntent() != null) { Log.i(TAG, "Launch intent = " + getIntent().getAction()); // If this is a launch through NFC tag reading if (getIntent().getAction() != null) { if (getIntent().getAction().equals("android.nfc.action.NDEF_DISCOVERED")) { // Save url which we got from NFC tag nfcTagData = getIntent().getDataString(); } } } // If we are in demo mode, ignore all settings and use demo url from strings if (settings.getBoolean("default_openhab_demomode", false)) { openHABBaseUrl = getString(R.string.openhab_demo_url); Log.i(TAG, "Demo mode, connecting to " + openHABBaseUrl); Toast.makeText(getApplicationContext(), getString(R.string.info_demo_mode), Toast.LENGTH_LONG) .show(); showTime(); } else { openHABBaseUrl = normalizeUrl(settings.getString("default_openhab_url", "")); // Check if we have a direct URL in preferences, if yes - use it if (openHABBaseUrl.length() > 0) { Log.i(TAG, "Connecting to configured URL = " + openHABBaseUrl); Toast.makeText(getApplicationContext(), getString(R.string.info_conn_url), Toast.LENGTH_SHORT) .show(); showTime(); } else { // Get current network information ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo != null) { Log.i(TAG, "Network is connected"); // If network is mobile, try to use remote URL if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE || serviceDiscoveryEnabled == false) { if (!serviceDiscoveryEnabled) { Log.i(TAG, "openHAB discovery is disabled"); } else { Log.i(TAG, "Network is Mobile (" + activeNetworkInfo.getSubtypeName() + ")"); } openHABBaseUrl = normalizeUrl(settings.getString("default_openhab_alturl", "")); // If remote URL is configured if (openHABBaseUrl.length() > 0) { Toast.makeText(getApplicationContext(), getString(R.string.info_conn_rem_url), Toast.LENGTH_SHORT).show(); Log.i(TAG, "Connecting to remote URL " + openHABBaseUrl); showTime(); } else { Toast.makeText(getApplicationContext(), getString(R.string.error_no_url), Toast.LENGTH_LONG).show(); } // If network is WiFi or Ethernet } if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI || activeNetworkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) { Log.i(TAG, "Network is WiFi or Ethernet"); // Start service discovery this.serviceResolver = new AsyncServiceResolver(this, openHABServiceType); progressDialog = ProgressDialog.show(this, "", "Discovering openHAB. Please wait...", true); this.serviceResolver.start(); // We don't know how to handle this network type } else { Log.i(TAG, "Network type (" + activeNetworkInfo.getTypeName() + ") is unsupported"); } // Network is not available } else { Log.i(TAG, "Network is not available"); Toast.makeText(getApplicationContext(), getString(R.string.error_network_not_available), Toast.LENGTH_LONG).show(); } } } } }
From source file:org.qeo.android.service.QeoService.java
private void configureNetworkSettings(NetworkInfo activeNetworkInfo) { if (activeNetworkInfo != null) { switch (activeNetworkInfo.getType()) { case ConnectivityManager.TYPE_ETHERNET: case ConnectivityManager.TYPE_WIFI: // only enable UDP on WIFI or ETHERNET LOG.fine("enable UDP"); NativeQeo.setUdpMode(true);//ww w . java2 s. c o m break; default: // disable UDP LOG.fine("disable UDP"); NativeQeo.setUdpMode(false); break; } } }
From source file:at.alladin.rmbt.android.util.InformationCollector.java
/** Returns the network that the phone is on (e.g. Wifi, Edge, GPRS, etc). */ public int getNetwork() { int result = TelephonyManager.NETWORK_TYPE_UNKNOWN; if (connManager != null) { final NetworkInfo activeNetworkInfo = connManager.getActiveNetworkInfo(); if (activeNetworkInfo != null) { final int type = activeNetworkInfo.getType(); switch (type) { case ConnectivityManager.TYPE_WIFI: result = NETWORK_WIFI;//from w w w.ja v a 2 s. c o m break; case ConnectivityManager.TYPE_BLUETOOTH: result = NETWORK_BLUETOOTH; break; case ConnectivityManager.TYPE_ETHERNET: result = NETWORK_ETHERNET; break; case ConnectivityManager.TYPE_MOBILE: case ConnectivityManager.TYPE_MOBILE_DUN: case ConnectivityManager.TYPE_MOBILE_HIPRI: case ConnectivityManager.TYPE_MOBILE_MMS: case ConnectivityManager.TYPE_MOBILE_SUPL: result = telManager.getNetworkType(); break; } } } /* detect change from wifi to mobile or reverse */ final int lastNetworkType = this.lastNetworkType.get(); if (result != TelephonyManager.NETWORK_TYPE_UNKNOWN && lastNetworkType != TelephonyManager.NETWORK_TYPE_UNKNOWN) { if ((result == ConnectivityManager.TYPE_WIFI && lastNetworkType != ConnectivityManager.TYPE_WIFI) || (result != ConnectivityManager.TYPE_WIFI && lastNetworkType == ConnectivityManager.TYPE_WIFI)) illegalNetworkTypeChangeDetcted.set(true); } if (result != lastNetworkType) { this.lastNetworkType.set(result); if (telListener != null) telListener.onSignalStrengthsChanged(null); } return result; }