get Scan Results By BSSID - Android android.net.wifi

Android examples for android.net.wifi:Wifi SSID

Description

get Scan Results By BSSID

Demo Code

import java.util.List;

import android.content.Context;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;

public class Main {

  public static ScanResult getScanResultsByBSSID(Context context, String bssid) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    ScanResult scanResult = null;//w ww . j ava  2s  .  co  m

    boolean f = wifiManager.startScan();
    if (!f) {
      getScanResultsByBSSID(context, bssid);
    }
    List<ScanResult> list = wifiManager.getScanResults();
    if (list != null) {
      for (int i = 0; i < list.size(); i++) {

        scanResult = list.get(i);
        if (scanResult.BSSID.equals(bssid)) {
          break;
        }
      }
    }
    return scanResult;
  }

  public static List<ScanResult> getScanResults(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    List<ScanResult> list = null;

    boolean f = wifiManager.startScan();
    if (!f) {
      getScanResults(context);
    } else {
      list = wifiManager.getScanResults();
    }

    return list;
  }

}

Related Tutorials