@Override protected void onStart() { Log.i(TAG, "Starting ServiceActivity..."); super.onStart(); try { Log.i(TAG, "Starting Mutlicast Lock..."); WifiManager wifi = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); // get the device ip address final InetAddress deviceIpAddress = getDeviceIpAddress(wifi); multicastLock = wifi.createMulticastLock(getClass().getName()); multicastLock.setReferenceCounted(true); multicastLock.acquire(); Log.i(TAG, "Starting ZeroConf probe...."); jmdns = JmDNS.create(deviceIpAddress, HOSTNAME); jmdns.addServiceTypeListener(this); } catch (IOException ex) { Log.e(TAG, ex.getMessage(), ex); } Log.i(TAG, "Started ZeroConf probe...."); }
protected void setWiFiMulticastLock(boolean enable) { if (multicastLock == null) { multicastLock = wifiManager.createMulticastLock(getClass().getSimpleName()); } if (enable) { if (multicastLock.isHeld()) { log.warning("WiFi multicast lock already acquired"); } else { log.info("WiFi multicast lock acquired"); multicastLock.acquire(); } } else { if (multicastLock.isHeld()) { log.info("WiFi multicast lock released"); multicastLock.release(); } else { log.warning("WiFi multicast lock already released"); } } }
@Test public void shouldCreateMulticastLock() throws Exception { assertThat(wifiManager.createMulticastLock("TAG")).isNotNull(); }
@Test public void shouldThrowRuntimeExceptionIfMulticastLockisUnderlocked() throws Exception { MulticastLock lock = wifiManager.createMulticastLock("TAG"); try{ lock.release(); fail("Expected exception"); } catch (RuntimeException expected) {}; }
@Test public void shouldThrowUnsupportedOperationIfMulticastLockisOverlocked() throws Exception { MulticastLock lock = wifiManager.createMulticastLock("TAG"); try { for (int i = 0; i < ShadowWifiManager.ShadowMulticastLock.MAX_ACTIVE_LOCKS; i++) { lock.acquire(); } fail("Expected exception"); } catch (UnsupportedOperationException e) { // expected } }
@Test public void shouldAcquireAndReleaseMulticastLockRefCounted() throws Exception { MulticastLock lock = wifiManager.createMulticastLock("TAG"); lock.acquire(); lock.acquire(); assertThat(lock.isHeld()).isTrue(); lock.release(); assertThat(lock.isHeld()).isTrue(); lock.release(); assertThat(lock.isHeld()).isFalse(); }
@Test public void shouldAcquireAndReleaseMulticastLockNonRefCounted() throws Exception { MulticastLock lock = wifiManager.createMulticastLock("TAG"); lock.setReferenceCounted(false); lock.acquire(); assertThat(lock.isHeld()).isTrue(); lock.acquire(); assertThat(lock.isHeld()).isTrue(); lock.release(); assertThat(lock.isHeld()).isFalse(); }
@Test public void multicastLockAcquireIncreasesActiveLockCount() throws Exception { MulticastLock lock = wifiManager.createMulticastLock("TAG"); assertThat(shadowOf(wifiManager).getActiveLockCount()).isEqualTo(0); lock.acquire(); assertThat(shadowOf(wifiManager).getActiveLockCount()).isEqualTo(1); lock.release(); assertThat(shadowOf(wifiManager).getActiveLockCount()).isEqualTo(0); }
WifiManager wifi = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); MulticastLock lock = wifi.createMulticastLock("dk.aboaya.pingpong"); lock.acquire(); serverSocket = new DatagramSocket(19876); serverSocket.setSoTimeout(15000); //15 sec wait for the client to connect byte[] data = new byte[UDPBatPositionUpdater.secretWord.length()]; DatagramPacket packet = new DatagramPacket(data, data.length); serverSocket.receive(packet); lock.release(); String s = new String(packet.getData()); System.out.println(s);
protected void setWiFiMulticastLock(boolean enable) { if (multicastLock == null) { multicastLock = wifiManager.createMulticastLock(getClass().getSimpleName()); } if (enable) { if (multicastLock.isHeld()) { log.warning("WiFi multicast lock already acquired"); } else { log.info("WiFi multicast lock acquired"); multicastLock.acquire(); } } else { if (multicastLock.isHeld()) { log.info("WiFi multicast lock released"); multicastLock.release(); } else { log.warning("WiFi multicast lock already released"); } } }
// Acquire multicast lock WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); MulticastLock multicastLock = wifi.createMulticastLock("multicastLock"); multicastLock.setReferenceCounted(true); multicastLock.acquire(); //Do some mutlicast job here ... ... // Once your finish using it, release multicast lock if (multicastLock != null) { multicastLock.release(); multicastLock = null; }
WifiManager wifi; wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); MulticastLock ml = wifi.createMulticastLock("just some tag text"); ml.acquire();
WifiManager wifi; wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); MulticastLock ml = wifi.createMulticastLock("just some tag text"); ml.acquire(); When the asynctask stops I do a ml.release();
WifiManager wifi; wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); MulticastLock wifilock = wifi.createMulticastLock("just some tag text"); wifilock.acquire();
WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE); MulticastLock lock = manager.createMulticastLock("lock name"); lock.setReferenceCounted(true); lock.acquire();
WifiManager wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE); if (wifi != null){ WifiManager.MulticastLock lock = wifi.createMulticastLock("mylock"); lock.acquire(); }
WifiManager wifi = (WifiManager)getSystemService( Context.WIFI_SERVICE ); if(wifi != null){ WifiManager.MulticastLock lock = wifi.createMulticastLock("Log_Tag"); lock.acquire(); }
public static boolean openWifiBrocast(Context context){ WifiManager wifiManager=(WifiManager)context.getSystemService(Context.WIFI_SERVICE); WifiManager.MulticastLock multicastLock=wifiManager.createMulticastLock("MediaPlayer"); if (multicastLock != null){ multicastLock.acquire(); return true; } return false; }
WifiManager wifi = (WifiManager)getSystemService( Context.WIFI_SERVICE ); if(wifi != null){ WifiManager.MulticastLock lock = wifi.createMulticastLock("Log_Tag"); lock.acquire(); }
WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE); WifiManager.MulticastLock multicastLock = wm.createMulticastLock("mydebuginfo"); multicastLock.acquire();