Hi all,
I tried to get the SSID of the connected network with this code:
Although I have in the manifest the permissions ACCESS_WIFI_STATE and ACCESS_FINE_LOCATION and
requested runtime permission ACCESS_FINE_LOCATION in the app and set on location of the device manually, the returned SSID is "unknownssid".
However I tried another way:
res.ssid returns the correct SSID of the connected network.
This is the documentation in Android developer WifiManger:
getConfiguredNetworks
added in API level 1
public List<WifiConfiguration> getConfiguredNetworks ()
Return a list of all the networks configured for the current foreground user. Not all fields of WifiConfiguration are returned. Only the following fields are filled in:
List<WifiConfiguration> a list of network configurations in the form of a list of WifiConfiguration objects.
I use in my code the field "status", which is NOT in the list above. But it seems to be filled, until Android 8 it works. Would it be filled in Android 9 too?
Thanks for answers
Lutz
I tried to get the SSID of the connected network with this code:
B4X:
...
Context.InitializeContext
Wifi = Context.RunMethod("getSystemService", Array("wifi"))
...
' if available and suplicantState "COMPLETED" return SSID
' if available and suplicantState <> "COMPLETED" return "not completed"
' if wifi is not enabled, Return "unknown ssid"
Public Sub returnActSSID As String
Dim SSID, state As String
Dim jo As JavaObject
jo = Wifi.RunMethodJO("getConnectionInfo", Null)
SSID = jo.RunMethod("getSSID", Null)
state = jo.RunMethod("getSupplicantState", Null)
If SSID <> "unknown ssid" Then
If state <> "COMPLETED" Then
SSID = "not completed"
End If
End If
Return SSID
End Sub
Although I have in the manifest the permissions ACCESS_WIFI_STATE and ACCESS_FINE_LOCATION and
requested runtime permission ACCESS_FINE_LOCATION in the app and set on location of the device manually, the returned SSID is "unknownssid".
However I tried another way:
B4X:
Type nwType (nwID As Int, ssid As String)
Sub GetConnectedNetwork As nwType
Dim nwList As List
Dim i As Int
Dim res As nwType
nwList = Wifi.RunMethodJO("getConfiguredNetworks", Null)
res.nwID = -1
res.ssid = "none"
For i = 0 To nwList.Size - 1
Dim config As JavaObject
config = nwList.Get(i)
If config.GetField("status") = 0 Then ' status = 0 is the CURRENT connected network!
res.nwID = config.GetField("networkId")
res.ssid = config.GetField("SSID")
Exit
End If
Next
Return res
End Sub
res.ssid returns the correct SSID of the connected network.
This is the documentation in Android developer WifiManger:
getConfiguredNetworks
added in API level 1
public List<WifiConfiguration> getConfiguredNetworks ()
Return a list of all the networks configured for the current foreground user. Not all fields of WifiConfiguration are returned. Only the following fields are filled in:
- networkId
- SSID
- BSSID
- priority
- allowedProtocols
- allowedKeyManagement
- allowedAuthAlgorithms
- allowedPairwiseCiphers
- allowedGroupCiphers
List<WifiConfiguration> a list of network configurations in the form of a list of WifiConfiguration objects.
I use in my code the field "status", which is NOT in the list above. But it seems to be filled, until Android 8 it works. Would it be filled in Android 9 too?
Thanks for answers
Lutz
Last edited: