I am developing an app in which I need to start a service when the WiFi is connected to a predefined SSID. Can anyone help me with this? Is there a broadcast in android that is fired when WiFi is connected (not turned on) ?
Asked
Active
Viewed 536 times
2 Answers
0
Yes, its called ConnectivityManager:
ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = conMan.getActiveNetworkInfo();
You can use getType() to check whether it is a WiFi connection:
netInfo.getType() == ConnectivityManager.TYPE_WIFI
See this post for more information.
EDIT
To obtain the SSID try:
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo connectionInfo = wifiManager.getConnectionInfo();
connectionInfo.getSSID();
as seen here

Community
- 1
- 1

Marcel Herd
- 392
- 1
- 8
-
And how would i check for the SSID it is connected to? – Simar Jan 11 '15 at 11:57
-
1I have edited the post since I can't figure out howto format comments – Marcel Herd Jan 11 '15 at 12:04
0
Yes, there's a Broadcast
for this: NETWORK_STATE_CHANGED_ACTION. When the new state is CONNECTED, the Intent
includes the BSSID as an extra (cf. the documentation linked above). You can check the state via the included NetworkInfo
object.

cygery
- 2,309
- 3
- 18
- 25