I am trying to implement a network monitor that will get the ssid of the wifi network connected.
public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) {
super.onCapabilitiesChanged(network, networkCapabilities);
// NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(network);
WifiInfo wifiInfo = (WifiInfo) networkCapabilities.getTransportInfo();
String ssid = wifiInfo.getSSID();
if (network != null && networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
if (ssid.startsWith("\"") && ssid.endsWith("\"")) {
Log.v(M_TAG, "ssid had quotations");
ssid = ssid.substring(1, ssid.length() - 1);
}
Log.v(M_TAG, ssid);
I have granted all location-wise permissions on runtime by default for my app and I have enabled location GPS on the device but still I am getting from the wifiINfo.getSSID().
Any ideas?
im also passing the FLAG_INCLUDE_LOCATION_INFO in my networkcallback:
networkCallback =
new ConnectivityManager.NetworkCallback(ConnectivityManager.NetworkCallback.FLAG_INCLUDE_LOCATION_INFO)