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:RhodesService.java
/** * This method is used only for non-Motorola devices as the UUID needs to be computed by other parameters. * @return 32-byte long UUID// www . j av a 2s . co m */ private static String computeUUID() { RhodesService srv = RhodesService.getInstance(); if (srv == null) throw new IllegalStateException("No rhodes service instance at this moment"); String res = ""; WifiManager wifi = (WifiManager) srv.getSystemService(Context.WIFI_SERVICE); // Get WiFi status WifiInfo wifiInfo = wifi.getConnectionInfo(); String macAddress = wifiInfo.getMacAddress(); macAddress = macAddress.replaceAll(":", ""); UUID localUuid = UUID.nameUUIDFromBytes(macAddress.getBytes()); res = localUuid.toString().replaceAll("-", ""); return res.toUpperCase(); }
From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java
/** * mDNS?./*from www .j av a2s . c o m*/ * */ public void searchDeviceByBonjour() { // cache?false???? // ?,???????, Wifi?Broadcast???? new Thread(new Runnable() { public void run() { services = new ArrayList<Bundle>(); android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) getSystemService( android.content.Context.WIFI_SERVICE); WifiManager.MulticastLock lock = wifi.createMulticastLock("deviceplugin.host"); lock.setReferenceCounted(true); lock.acquire(); } }).start(); }
From source file:com.grazerss.EntryManager.java
boolean isOnWiFi() { if (connectivityManager == null) { connectivityManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); }// w w w. j ava2s . co m if (connectivityManager == null) { PL.log("EntryManager. Wasn't able to get CONNECTIVITY_SERVICE.", ctx); WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { PL.log("WiFi Info=" + wifiInfo + " SSID=" + wifiInfo.getSSID(), ctx); } return false; } final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo == null) { PL.log("EntryManager. Wasn't able to get Network Info.", ctx); return false; } if (ConnectivityManager.TYPE_WIFI != networkInfo.getType()) { PL.log("EntryManager. Network Info Type was not WiFi, but " + networkInfo.getType() + ".", ctx); return false; } return true; }
From source file:com.intel.xdk.device.Device.java
private String getConnection() { WifiManager wifiMgr = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE); if (wifiMgr.isWifiEnabled() == true) { return "wifi"; }//w ww . j a v a 2 s . c o m TelephonyManager telMgr = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE); int data = telMgr.getDataState(); if (data == TelephonyManager.DATA_DISCONNECTED || data == TelephonyManager.DATA_SUSPENDED) return "none"; else return "cell"; }
From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java
/** * mDNS??????.// w ww .j a va 2 s. co m * */ public void invokeDeviceByBonjour() { // cache?false???? // ?,???????, Wifi?Broadcast???? new Thread(new Runnable() { public void run() { services = new ArrayList<Bundle>(); android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) getSystemService( android.content.Context.WIFI_SERVICE); WifiManager.MulticastLock lock = wifi.createMulticastLock("deviceplugin.host"); lock.setReferenceCounted(true); lock.acquire(); } }).start(); }
From source file:com.newsrob.EntryManager.java
boolean isOnWiFi() { if (connectivityManager == null) connectivityManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager == null) { PL.log("EntryManager. Wasn't able to get CONNECTIVITY_SERVICE.", ctx); WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) PL.log("WiFi Info=" + wifiInfo + " SSID=" + wifiInfo.getSSID(), ctx); return false; }/*from w w w . j a v a2 s . c o m*/ final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo == null) { PL.log("EntryManager. Wasn't able to get Network Info.", ctx); return false; } if (ConnectivityManager.TYPE_WIFI != networkInfo.getType()) { PL.log("EntryManager. Network Info Type was not WiFi, but " + networkInfo.getType() + ".", ctx); return false; } return true; }
From source file:com.moez.QKSMS.mmssms.Transaction.java
/** * @deprecated//ww w.ja v a 2 s .com */ private void reinstateWifi() { try { context.unregisterReceiver(settings.discon); } catch (Exception f) { } WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifi.setWifiEnabled(false); wifi.setWifiEnabled(settings.currentWifiState); wifi.reconnect(); Utils.setMobileDataEnabled(context, settings.currentDataState); }
From source file:com.moez.QKSMS.mmssms.Transaction.java
/** * @deprecated// ww w . ja v a 2 s . co m */ private void revokeWifi(boolean saveState) { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (saveState) { settings.currentWifi = wifi.getConnectionInfo(); settings.currentWifiState = wifi.isWifiEnabled(); wifi.disconnect(); settings.discon = new DisconnectWifi(); context.registerReceiver(settings.discon, new IntentFilter(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)); settings.currentDataState = Utils.isMobileDataEnabled(context); Utils.setMobileDataEnabled(context, true); } else { wifi.disconnect(); wifi.disconnect(); settings.discon = new DisconnectWifi(); context.registerReceiver(settings.discon, new IntentFilter(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)); Utils.setMobileDataEnabled(context, true); } }
From source file:com.csipsimple.service.SipService.java
/** * Ask to take the control of the wifi and the partial wake lock if * configured//from w w w.j a v a 2s.c o m */ private synchronized void acquireResources() { if (holdResources) { return; } // Add a wake lock for CPU if necessary if (prefsWrapper.getPreferenceBooleanValue(SipConfigManager.USE_PARTIAL_WAKE_LOCK)) { PowerManager pman = (PowerManager) getSystemService(Context.POWER_SERVICE); if (wakeLock == null) { wakeLock = pman.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "com.csipsimple.SipService"); wakeLock.setReferenceCounted(false); } // Extra check if set reference counted is false ??? if (!wakeLock.isHeld()) { wakeLock.acquire(); } } // Add a lock for WIFI if necessary WifiManager wman = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (wifiLock == null) { int mode = WifiManager.WIFI_MODE_FULL; if (Compatibility.isCompatible(9) && prefsWrapper.getPreferenceBooleanValue(SipConfigManager.LOCK_WIFI_PERFS)) { mode = 0x3; // WIFI_MODE_FULL_HIGH_PERF } wifiLock = wman.createWifiLock(mode, "com.csipsimple.SipService"); wifiLock.setReferenceCounted(false); } if (prefsWrapper.getPreferenceBooleanValue(SipConfigManager.LOCK_WIFI) && !wifiLock.isHeld()) { WifiInfo winfo = wman.getConnectionInfo(); if (winfo != null) { DetailedState dstate = WifiInfo.getDetailedStateOf(winfo.getSupplicantState()); // We assume that if obtaining ip addr, we are almost connected // so can keep wifi lock if (dstate == DetailedState.OBTAINING_IPADDR || dstate == DetailedState.CONNECTED) { if (!wifiLock.isHeld()) { wifiLock.acquire(); } } } } holdResources = true; }
From source file:com.android.launcher3.Utilities.java
public static void turnOnWifi(Activity activity) { WifiManager wifimanager = (WifiManager) activity.getApplicationContext() .getSystemService(Context.WIFI_SERVICE); wifimanager.setWifiEnabled(true);//from w w w .jav a 2 s . c om isWifiOn = true; }