2013/02/11

Automatically connect to any unsecured Wi-Fi AP from Android

For a long time I wanted my phone to just connect to any SSID which has no password set. I'm travelling often and don't have mobile internet most of the time, and I want my phone to sync emails and stuff whenever I get to the vicinity of a publicly available Wi-Fi signal without touching my phone. Google didn't help, but I finally figured it out accidentally when searching for a solution to extract cleartext Wi-Fi passwords from my phone.

You will need to edit the file /data/misc/wifi/wpa_supplicant.conf and add the following lines:
# This is a network block that connects to any unsecured access point.
# We give it a low priority so any defined blocks are preferred.
network={
        key_mgmt=NONE
        priority=-9
}

I recommend switching off Wi-Fi first, because this file gets updated automatically. There is a drawback though, on the AP list, you won't see which SSID you are connected to, and QuickSettings will say "Connected to (null)". But it works.

PS: You need a rooted phone for this, the wpa_supplicant.conf is not writable (and not even readable) otherwise.