Code example for WifiManager

Methods: createWifiLockisWifiEnabledstartScan

    if (listening) return;
    // We only get onProviderDisabled() when we start listening. 
    enabled = isEnabled();
    // TODO(yuhan): do we need this lock? 
    wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY,
    // TODO(yuhan): does this do one scan, or does it scan continuously? if it 
    //     only does one scan, we should probably make this a measurement; I 
    //     know active scanning requires sending out data packets, so it might 
    //     be super-expensive 
    listening = true;
   * Stops listening for location updates. 
   * This should be called when your application / activity is no longer active. 
  public static void stop() { 
    if (!listening) return;
    wifiLock = null;
    listening = false;
   * Checks if the user's preferences allow the use of WiFi. 
   * @return true if the user lets us use WiFi 
  public static boolean isEnabled() { 
    return wifiManager.isWifiEnabled();
   * Writes a JSON representation of the WiFi data to the given buffer.