4

I use the following code to get BSSID:

public static String getBSSID(Context context) {
    WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    return wifiMgr.getConnectionInfo().getBSSID();
}

When i use this code when the device doesn't have sim card it works fine. But when i have a sim card, even when i am using wifi - me returned value is 00:00:00:00:00:00. Anybody knows why it happens?

Zbun
  • 4,875
  • 4
  • 19
  • 28
  • 1
    When you are "using wifi" are you actually connected to an AP, or is Wifi just turned on? – Larry Schiefer Jul 15 '14 at 10:40
  • Does the `WifiInfo` object provide any other valid data? – Larry Schiefer Jul 15 '14 at 11:22
  • well it does. But now i also get my bssid right... I have no idea why it dodn't work all day on 2 different devices, but maybe i just had problems with my wifi and i didn't notice.. thanks for the help! – Zbun Jul 15 '14 at 11:43

1 Answers1

1

had same problem myself. most of the chances is that you are not checking if you are currently connected to the WiFi before attempting to get the bssid:

public static boolean isConnectedToRouter(Context context) {
    ConnectivityManager onnectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo wifi = onnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    if (wifi.isConnected()) {
        return true;
    }

    return false;
}

only if this method returns true, then you can obtain bssid. attemping to get BSSID when you are not connected to specific Wifi will return 00:00:00:00:00:00

Tal Kanel
  • 10,475
  • 10
  • 60
  • 98