4

It looks like one feature coming out in 8.0 Android O is the ability to Automatically enable WiFi when you're near a saved network

Android O - Auto Enable Wifi

Can this be accomplished through tasker today?

  1. Add Profile > State > Net > Wifi Near (as in these questions here and here)

    Profile > State > Net > Wifi Near

  2. Enter SSID Network Name(s) / Select Networks currently in Range

    SSID Network Names

  3. This works one at a time, but ideally, you could pull from the current list of saved/configured WiFi networks. Android does keep a list of previously saved networks:

    Saved Networks

Q: But is there anyway to programmatically retrieve all saved network names and set it as a variable?

Note: Some apps exist like SmartWifiToggler, based on GPS, but I'd rather accomplish through tasker if possible.

9
  • If I am not mistaken, you dont have to necessarily specify the Wireless AP, this way all near Wireless APs are considered (with one having strongest signal choosen) given that there are saved in android system settings Commented May 18, 2017 at 15:02
  • How is using WiFi signals to determine whether you should "enable WiFi" different from having WiFi on to begin with? You will use saved WiFi networks when they are available, and scan in the background when not near a saved network.
    – mattm
    Commented May 18, 2017 at 15:42
  • @xavier_fakerat, the goal is to enable WiFi when I'm near any network that I have saved and disable it everywhere else.
    – KyleMit
    Commented May 18, 2017 at 15:47
  • @mattm, the problem is when I have WiFi on while walking around, it will often get stuck at a log-in screen and interrupt wireless access until I've either logged in or turned off wifi. I find it generally easier to just have it turned off unless I'm at home (or list of similar locations where I trust the WiFi).
    – KyleMit
    Commented May 18, 2017 at 15:47
  • 1
    I just happen to have bumped into a similar scenario you wish to have: Tasker double WiFi activation with 'or' statement, it seems there are many possibilities to accomplish this....will update you once I finish testing my profile on this Commented May 18, 2017 at 17:22

2 Answers 2

3

I had same issue and finally found a link to this project: https://www.reddit.com/r/tasker/comments/8p0ywt/project_share_switching_to_saved_wifi/ The project itself does a bit more, but shows one way to get the saved wifis with default Tasker features.

So regarding your Q: But is there anyway to programmatically retrieve all saved network names and set it as a variable?

A: Yes, there is, using Tasker action of type Code -> Java Function (see also function $getConfiguredNetworks in the linked project):

1.) Use Code Java Function to get WifiManager from CONTEXT

2.) Use Code Java Function to get configured networks from WifiManager

3.-6.) Use Variable Search Replace to get SSIDs out of the configured networks using regular expression

7.-8.) Set variable to be checked by Tasker Wifi Near State

9.) (Optional) Trigger steps 1-8 automatically

Detailed Tasker actions:

1.) Java Function:

a) Class Or Object=CONTEXT

b) Function=getSystemService{Object}(String) <select using magnifying glass icon and either scroll down or use filter on the bottom of the screen, pay attention to not pick the (Class) version>

c) Param=wifi

d) Return{Object}=(WifiManager) wifiman

--> result in Tasker view should look like this: (WifiManager) wifiman = CONTEXT.getSystemService(wifi)

2.) Java Function:

a) Class Or Object=wifiman

b) Function=getConfiguredNetworks{List}()

c) Return{List}=%get_configured_networks

--> result in Tasker view should look like this: %get_configured_networks = wifiman.getConfiguredNetworks()

Extract SSIDs, there are many ways, I did it looping over the list

3.) For: Variable %get_configured_networks Items %configured_network

Delete everyting from the variable that is not the SSID using regular expression

4.) Variable Search Replace:

a) Variable=%configured_network

b) Search=(?:.|\n)*SSID:\s*"(.*)"(?:.|\n)* <this regex will capture the SSID name in capture group 1>

c) Replace Matches=true

d) Replace with=$1

Add SSID to array

5.) Array Push: Variable Array %ssids Position 1 Value %configured_network

End loop

6.) End For

Join SSIDs with / as separator to fit Taskers wifi near syntax SSID1/SSID2/.../SSIDn

7.) Variable Join %ssids Joiner /

Set Global Variable to be checked by Taskers Wifi Near State

8.) Variable Set Name %SavedWifis To %ssids

So once this is done, a Wifi Near %SavedWifis can be used. But after you have added a new Wifi or removed an old one, you need to update the value again.

9.) Execute Taks to refresh %SavedWifis regularly (for example based on time event or whenever wifi connected), if anybody knows a way to react on a 'savedWifisUpdated' event, please let me know. enter image description here

0
0

Check out the app called IFTTT, I believe they have something like that where you can set that up.

1
  • While this answer might help, unfortunately it's still too short on the detail. What should the readers do after installing IFTTT? Instead of finding "something like that", how to properly set up the app to do what the asker wants?
    – Andrew T.
    Commented Feb 3, 2021 at 21:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .