android.net.wifi.WifiManager.createMulticastLock()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(195)

本文整理了Java中android.net.wifi.WifiManager.createMulticastLock()方法的一些代码示例,展示了WifiManager.createMulticastLock()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WifiManager.createMulticastLock()方法的具体详情如下:
包路径:android.net.wifi.WifiManager
类名称:WifiManager
方法名:createMulticastLock

WifiManager.createMulticastLock介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

@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....");
}

代码示例来源:origin: 4thline/cling

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");
    }
  }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldCreateMulticastLock() throws Exception {
 assertThat(wifiManager.createMulticastLock("TAG")).isNotNull();
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldThrowRuntimeExceptionIfMulticastLockisUnderlocked() throws Exception {
 MulticastLock lock = wifiManager.createMulticastLock("TAG");
 try{
  lock.release();
  fail("Expected exception");
 } catch (RuntimeException expected) {};
}

代码示例来源:origin: robolectric/robolectric

@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
 }
}

代码示例来源:origin: robolectric/robolectric

@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();
}

代码示例来源:origin: robolectric/robolectric

@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();
}

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源:origin: stackoverflow.com

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);

代码示例来源:origin: kingthy/TVRemoteIME

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");
    }
  }
}

代码示例来源:origin: stackoverflow.com

// 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;
}

代码示例来源:origin: stackoverflow.com

WifiManager wifi;
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
MulticastLock ml = wifi.createMulticastLock("just some tag text");
ml.acquire();

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: stackoverflow.com

WifiManager wifi;
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
MulticastLock wifilock = wifi.createMulticastLock("just some tag text");
wifilock.acquire();

代码示例来源:origin: stackoverflow.com

WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
MulticastLock lock = manager.createMulticastLock("lock name");
lock.setReferenceCounted(true);
lock.acquire();

代码示例来源:origin: stackoverflow.com

WifiManager wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
 if (wifi != null){
   WifiManager.MulticastLock lock = wifi.createMulticastLock("mylock");
   lock.acquire();
 }

代码示例来源:origin: stackoverflow.com

WifiManager wifi = (WifiManager)getSystemService( Context.WIFI_SERVICE );
if(wifi != null){
  WifiManager.MulticastLock lock = wifi.createMulticastLock("Log_Tag");
  lock.acquire();
}

代码示例来源:origin: geniusgithub/MediaPlayer

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;
}

代码示例来源:origin: stackoverflow.com

WifiManager wifi = (WifiManager)getSystemService( Context.WIFI_SERVICE );
if(wifi != null){
WifiManager.MulticastLock lock = wifi.createMulticastLock("Log_Tag");
lock.acquire();
}

代码示例来源:origin: stackoverflow.com

WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
WifiManager.MulticastLock multicastLock = wm.createMulticastLock("mydebuginfo");
multicastLock.acquire();

相关文章