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

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

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

WifiManager.createWifiLock介绍

暂无

代码示例

代码示例来源:origin: google/ExoPlayer

@Override
public void onStart() {
 Context appContext = getApplicationContext();
 WifiManager wifiManager = (WifiManager) appContext.getSystemService(Context.WIFI_SERVICE);
 wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, TAG);
 wifiLock.acquire();
 PowerManager powerManager = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE);
 wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
 wakeLock.acquire();
 super.onStart();
}

代码示例来源:origin: TeamNewPipe/NewPipe

public void acquireWifiAndCpu() {
  Log.d(TAG, "acquireWifiAndCpu() called");
  if (wakeLock != null && wakeLock.isHeld() && wifiLock != null && wifiLock.isHeld()) return;
  wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
  wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, TAG);
  if (wakeLock != null) wakeLock.acquire();
  if (wifiLock != null) wifiLock.acquire();
}

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

protected void setWifiLock(boolean enable) {
  if (wifiLock == null) {
    wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, getClass().getSimpleName());
  }
  if (enable) {
    if (wifiLock.isHeld()) {
      log.warning("WiFi lock already acquired");
    } else {
      log.info("WiFi lock acquired");
      wifiLock.acquire();
    }
  } else {
    if (wifiLock.isHeld()) {
      log.info("WiFi lock released");
      wifiLock.release();
    } else {
      log.warning("WiFi lock already released");
    }
  }
}

代码示例来源:origin: google/ExoPlayer

@Override
public void onStart() {
 Context appContext = getApplicationContext();
 WifiManager wifiManager = (WifiManager) appContext.getSystemService(Context.WIFI_SERVICE);
 wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, TAG);
 wifiLock.acquire();
 PowerManager powerManager = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE);
 wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
 wakeLock.acquire();
 super.onStart();
}

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

@Test
public void shouldCreateWifiLock() throws Exception {
 assertThat(wifiManager.createWifiLock("TAG")).isNotNull();
 assertThat(wifiManager.createWifiLock(1, "TAG")).isNotNull();
}

代码示例来源:origin: termux/termux-app

mWifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, EmulatorDebug.LOG_TAG);
mWifiLock.acquire();

代码示例来源:origin: cSploit/android

mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "wifiLock");

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

@Test
public void shouldThrowUnsupportedOperationIfWifiLockisOverlocked() throws Exception {
 WifiManager.WifiLock lock = wifiManager.createWifiLock("TAG");
 try {
  for (int i = 0; i < ShadowWifiManager.ShadowWifiLock.MAX_ACTIVE_LOCKS; i++) {
   lock.acquire();
  }
  fail("UnsupportedOperationException not thrown");
 } catch (UnsupportedOperationException e) {
  // expected
 }
}

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

@Test
public void shouldThrowRuntimeExceptionIfWifiLockisUnderlocked() throws Exception {
 WifiManager.WifiLock lock = wifiManager.createWifiLock("TAG");
 try {
  lock.release();
  fail("RuntimeException not thrown");
 } catch (RuntimeException e) {
  // expected
 }
}

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

@Test
public void shouldAcquireAndReleaseWifilockNonRefCounted() throws Exception {
 WifiManager.WifiLock lock = wifiManager.createWifiLock("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 shouldAcquireAndReleaseWifilockRefCounted() throws Exception {
 WifiManager.WifiLock lock = wifiManager.createWifiLock("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 wifiLockAcquireIncreasesActiveLockCount() throws Exception {
 WifiManager.WifiLock lock = wifiManager.createWifiLock("TAG");
 assertThat(shadowOf(wifiManager).getActiveLockCount()).isEqualTo(0);
 lock.acquire();
 assertThat(shadowOf(wifiManager).getActiveLockCount()).isEqualTo(1);
 lock.release();
 assertThat(shadowOf(wifiManager).getActiveLockCount()).isEqualTo(0);
}

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

protected WifiManager.WifiLock createWiFiLock() {
  int wifiMode = WifiManager.WIFI_MODE_FULL;
  try {
    // TODO: What's this?
    Field f = WifiManager.class.getField("WIFI_MODE_FULL_HIGH_PERF");
    wifiMode = f.getInt(null);
  } catch (Exception e) {
    // Ignore
  }
  WifiManager.WifiLock wifiLock =
    wifiManager.createWifiLock(wifiMode, getClass().getSimpleName());
  log.info("Created WiFi lock, mode: " + wifiMode);
  return wifiLock;
}

代码示例来源:origin: jberkel/sms-backup-plus

protected synchronized void acquireLocks() {
  if (wakeLock == null) {
    PowerManager pMgr = (PowerManager) getSystemService(POWER_SERVICE);
    wakeLock = pMgr.newWakeLock(wakeLockType(), "com.zegoggles.smssync:"+TAG);
  }
  wakeLock.acquire(10*60*1000L /*10 minutes*/);
  if (isConnectedViaWifi()) {
    // we have Wifi, lock it
    WifiManager wMgr = getWifiManager();
    if (wifiLock == null) {
      wifiLock = wMgr.createWifiLock(getWifiLockType(), TAG);
    }
    wifiLock.acquire();
  }
}

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

WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiLock= wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "TAG");
wifiLock.acquire();

// When you are done
wifiLock.release();

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

WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiLock wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY , "MyWifiLock");
if(!wifiLock.isHeld()){
  wifiLock.acquire();
}

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

WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);
WifiLock wifiLock = wifiManager.createWifiLock("long_download");
wifiLock.acquire();
// Do the heavy work in background
wifiLock.release();

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

WifiManager wifimanager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
WifiLock lock = wifimanager.createWifiLock("my_lock");

lock.acquire();

// your code here

lock.release();

代码示例来源:origin: TeamFatCat/Easy_Transfer

/**
 * 构造函数
 *
 * @param context
 */
public WifiAdmin(Context context) {
  mContext = context;
  mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
  mWifiLock = mWifiManager.createWifiLock(WIFI_LOCK_TAG);
}

代码示例来源:origin: limboemu/limbo

private void setupLocks() {
  mWifiLock = ((WifiManager) service.getApplicationContext().getSystemService(Context.WIFI_SERVICE))
      .createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, Config.wifiLockTag);
  mWifiLock.setReferenceCounted(false);
  PowerManager pm = (PowerManager) service.getApplicationContext().getSystemService(Context.POWER_SERVICE);
  mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Config.wakeLockTag);
  mWakeLock.setReferenceCounted(false);
  mNotificationManager = (NotificationManager) service.getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
}

相关文章