WifiManager returns BSSID 00: 00: 00: 00: 00: 00

I use the following code to get the 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 does not have a SIM card, it works fine. But when I have a SIM card, even when I use Wi-Fi, the value 00: 00: 00: 00: 00: 00 is returned to me. Does anyone know why this happens?

+4
source share
1 answer

was the problem itself. most of them are that you do not check if you are connected to Wi-Fi before trying to get 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, can you get bssid. to get the BSSID when you are not connected to a specific Wi-Fi, it will return 00: 00: 00: 00: 00: 00

+1
source

Source: https://habr.com/ru/post/1548468/


All Articles