List of usage examples for android.content Context WIFI_SERVICE
String WIFI_SERVICE
To view the source code for android.content Context WIFI_SERVICE.
Click Source Link
From source file:github.daneren2005.serverproxy.ServerProxy.java
public String getPublicAddress(String request) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); int ipAddress = wifiManager.getConnectionInfo().getIpAddress(); if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { ipAddress = Integer.reverseBytes(ipAddress); }// w ww . java 2s .co m byte[] ipByteArray = BigInteger.valueOf(ipAddress).toByteArray(); String ipAddressString = null; try { ipAddressString = InetAddress.getByAddress(ipByteArray).getHostAddress(); } catch (UnknownHostException ex) { Log.e(TAG, "Unable to get host address."); } return getAddress(ipAddressString, request); }
From source file:com.conferenceengineer.android.iosched.util.WiFiUtils.java
/** * Helper method to decide whether to bypass conference WiFi setup. Return true if * WiFi AP is already configured (WiFi adapter enabled) or WiFi configuration is complete * as per shared preference.//www .j a v a2s . co m */ public static boolean shouldBypassWiFiSetup(final Context context) { final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); // Is WiFi on? if (wifiManager.isWifiEnabled()) { // Check for existing APs. final List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks(); final String conferenceSSID = String.format("\"%s\"", Config.WIFI_SSID); for (WifiConfiguration config : configs) { if (conferenceSSID.equalsIgnoreCase(config.SSID)) return true; } } return WIFI_CONFIG_DONE.equals(getWiFiConfigStatus(context)); }
From source file:org.openremote.android.test.console.net.ORNetworkCheckTest.java
public void setUp() { this.ctx = getInstrumentation().getTargetContext(); wifi = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); enableWifi();// w ww . ja v a2 s .c o m AppSettingsModel.setCurrentPanelIdentity(ctx, null); }
From source file:foam.starwisp.NetworkManager.java
void Start(String ssid, StarwispActivity c, String name, StarwispBuilder b) { Log.i("starwisp", "Network startup!"); m_CallbackName = name;// w w w. ja v a2 s . c om m_Context = c; m_Builder = b; if (state == NetworkManager.State.IDLE) { Log.i("starwisp", "State is idle, launching scan"); wifi = (WifiManager) c.getSystemService(Context.WIFI_SERVICE); state = State.SCANNING; SSID = ssid; wifi.startScan(); receiver = new WiFiScanReceiver(SSID, this); c.registerReceiver(receiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); // todo - won't work from inside fragments m_Builder.DialogCallback(m_Context, m_Context.m_Name, m_CallbackName, "\"Scanning\""); } if (state == NetworkManager.State.CONNECTED) { Log.i("starwisp", "State is connected, callback raised"); m_Builder.DialogCallback(m_Context, m_Context.m_Name, m_CallbackName, "\"Connected\""); } }
From source file:it.evilsocket.dsploit.net.Network.java
public Network(Context context) throws NoRouteToHostException, SocketException, UnknownHostException { mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); mInfo = mWifiManager.getDhcpInfo();//from w w w . j a v a2 s . c o m mWifiInfo = mWifiManager.getConnectionInfo(); mLocal = new IP4Address(mInfo.ipAddress); mGateway = new IP4Address(mInfo.gateway); mNetmask = getNetmask(); mBase = new IP4Address(mInfo.netmask & mInfo.gateway); if (isConnected() == false) throw new NoRouteToHostException("Not connected to any WiFi access point."); else { try { mInterface = NetworkInterface.getByInetAddress(getLocalAddress()); if (mInterface == null) throw new IllegalStateException("Error retrieving network interface."); } catch (SocketException e) { System.errorLogging(e); /* * Issue #26: Initialization error in ColdFusionX ROM * * It seems it's a ROM issue which doesn't correctly populate device descriptors. * This rom maps the default wifi interface to a generic usb device * ( maybe it's missing the specific interface driver ), which is obviously not, and * it all goes shit, use an alternative method to obtain the interface object. */ mInterface = NetworkInterface.getByName(java.lang.System.getProperty("wifi.interface", "wlan0")); if (mInterface == null) throw e; } } }
From source file:fr.inria.ucn.Helpers.java
/** * Acquire the wifi wakelock./*w w w. ja v a 2 s .c o m*/ * @param c */ public static synchronized void acquireWifiLock(Context c) { WifiManager mgr = (WifiManager) c.getSystemService(Context.WIFI_SERVICE); if (wifilock == null) { wifilock = mgr.createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY, "ucn"); wifilock.setReferenceCounted(false); } Log.d(Constants.LOGTAG, "acquire wifilock"); wifilock.acquire(); acquireLock(c); }
From source file:org.csploit.android.net.Network.java
public Network(Context context) throws SocketException, UnknownHostException { mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); mInfo = mWifiManager.getDhcpInfo();// ww w. ja va 2s.c o m mWifiInfo = mWifiManager.getConnectionInfo(); mLocal = new IP4Address(mInfo.ipAddress); mGateway = new IP4Address(mInfo.gateway); mNetmask = getNetmask(); mBase = new IP4Address(mInfo.netmask & mInfo.gateway); if (isConnected() == false) throw new NoRouteToHostException("Not connected to any WiFi access point."); else { try { mInterface = NetworkInterface.getByInetAddress(getLocalAddress()); if (mInterface == null) throw new IllegalStateException("Error retrieving network interface."); } catch (SocketException e) { System.errorLogging(e); /* * Issue #26: Initialization error in ColdFusionX ROM * * It seems it's a ROM issue which doesn't correctly populate device descriptors. * This rom maps the default wifi interface to a generic usb device * ( maybe it's missing the specific interface driver ), which is obviously not, and * it all goes shit, use an alternative method to obtain the interface object. */ mInterface = NetworkInterface.getByName(java.lang.System.getProperty("wifi.interface", "wlan0")); if (mInterface == null) throw e; } } }
From source file:com.binomed.showtime.android.util.localisation.LocationUtils.java
public static boolean isLocalisationEnabled(Context context, ProviderEnum provider) { boolean result = false; switch (provider) { case GPS_PROVIDER: case GSM_PROVIDER: { LocationManager locationManager = getLocationManager(context); if (locationManager != null) { try { result = locationManager.isProviderEnabled(provider.getAndroidProvider()); } catch (Exception e) { result = false;//from www . java 2s. c om } } break; } case XPS_PROVIDER: { LocationManager locationManager = getLocationManager(context); WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if ((locationManager != null) && (wm != null)) { try { result = (locationManager.isProviderEnabled(ProviderEnum.GPS_PROVIDER.getAndroidProvider()) // || locationManager.isProviderEnabled(ProviderEnum.GSM_PROVIDER.getAndroidProvider())) // && wm.isWifiEnabled(); } catch (Exception e) { result = false; } } break; } case WIFI_PROVIDER: { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wm != null) { result = wm.isWifiEnabled(); } break; } case IP_PROVIDER: { result = true; break; } default: break; } return result; }
From source file:com.vinexs.tool.NetworkManager.java
public static InetAddress getInetAddress(Context context) { if (haveNetwork(context)) { return null; }//from w ww .j av a 2s . co m if (isWifiNetwork(context)) { int ipAddress = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)).getConnectionInfo() .getIpAddress(); if (ipAddress == 0) { return null; } return intToInet(ipAddress); } try { Enumeration<NetworkInterface> netinterfaces = NetworkInterface.getNetworkInterfaces(); while (netinterfaces.hasMoreElements()) { NetworkInterface netinterface = netinterfaces.nextElement(); Enumeration<InetAddress> adresses = netinterface.getInetAddresses(); while (adresses.hasMoreElements()) { InetAddress address = adresses.nextElement(); if (!address.isLoopbackAddress() && !address.isLinkLocalAddress()) { return address; } } } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.adamkruger.myipaddressinfo.NetworkInfoFragment.java
private void refreshData() { Context context = getActivity(); ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); mNetworkInfo = connectivityManager.getActiveNetworkInfo(); mNetworkInterfaceInfos = getNetworkInterfaceInfos(); mDNSes = getActiveNetworkDnsResolvers(context); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mWifiEnabled = wifiManager.isWifiEnabled(); mWifiInfo = wifiManager.getConnectionInfo(); mDhcpInfo = wifiManager.getDhcpInfo(); }