Trying to get SSID of current connected Wifi AP as global variable

Post your questions and help other users.

Moderator: Martin

Post Reply
p50kombi
Posts: 18
Joined: 05 Feb 2016 23:23

Trying to get SSID of current connected Wifi AP as global variable

Post by p50kombi » 10 Mar 2020 14:21

Hi All,

I am trying to get the name of the Wifi network I am currently connected to in a widget on screen.
I use this widget to swich wifi on and off and to show what I am connected to atm.
I found a bit of code on here and adapted it as follows:

Code: Select all

wifiManager=callJavaMethod(getContext(), "android.content.Context", "getSystemService(java.lang.String)", "wifi");
scanResults=callJavaMethod(wifiManager, "android.net.wifi.WifiManager", "getScanResults()");

for(sr in scanResults)
{
  global_network_ssid=getJavaField(sr, "android.net.wifi.ScanResult", "SSID");

}
but that just shows a randon name of one of the networks available as it just picks one at random of all the networks it scans.
I also know I can get the name of the current connected SSID from WifiInfo#getSSID which I found on here:
https://developer.android.com/reference ... i/WifiInfo
but I can't seem to figure out (as I have no coding background) how to adapt above script to write the global_network_ssid as the value of getSSID

Any help would be greatly appreciated, thanks very much...

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: Trying to get SSID of current connected Wifi AP as global variable

Post by anuraag » 10 Mar 2020 14:38

There is an condition WiFi Connected available to get currently connected ssid. It will give you ssid variable.

p50kombi
Posts: 18
Joined: 05 Feb 2016 23:23

Re: Trying to get SSID of current connected Wifi AP as global variable

Post by p50kombi » 10 Mar 2020 14:49

Thanks, now only thing is which script do I use to let global_wifi_ssid be the variable ssid?

for some reason my brain is having a meltdown.

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: Trying to get SSID of current connected Wifi AP as global variable

Post by anuraag » 10 Mar 2020 14:52

Use script action after above condition. Put

Code: Select all

global_wifi_ssid = ssid

p50kombi
Posts: 18
Joined: 05 Feb 2016 23:23

Re: Trying to get SSID of current connected Wifi AP as global variable

Post by p50kombi » 10 Mar 2020 14:54

tried that, that just gives the global variable out as ssid for some reason

p50kombi
Posts: 18
Joined: 05 Feb 2016 23:23

Re: Trying to get SSID of current connected Wifi AP as global variable

Post by p50kombi » 10 Mar 2020 14:57

sorry, gives the value as null, not ssid

p50kombi
Posts: 18
Joined: 05 Feb 2016 23:23

Re: Trying to get SSID of current connected Wifi AP as global variable

Post by p50kombi » 10 Mar 2020 15:07

sorted it, I used it as a trigger, not as a condition.
using at a condition, now the script works.

Thanks for your help.

Post Reply