1

I am writing an android app and trying to figure out if there is a reliable way to determine when the phone is on a specific wifi network.

For example, I want to perform certain actions only when connected to the home wifi.

Does anyone know if it's possible?

user1094206
  • 920
  • 1
  • 12
  • 24
  • both responses for this question are partially wrong, sometime when you try to get the ssid it apears x0 in the ssid, or null. they are not 100% reliables awnsers – xanexpt Jun 22 '16 at 13:25

2 Answers2

2

Yes, there is a way for this on both, android and iOS/iPhone.

On Android, you need to use this method in the end: android.net.wifi.WifiInfo.getSSID

On iPhone it's a completely different world. You can find a good description of how to do it here: iPhone get SSID without private library

Community
  • 1
  • 1
Daniel S.
  • 6,458
  • 4
  • 35
  • 78
  • Thanks for your answer, Daniel. I am also very concerned about the security aspect of this. I don't have much background in Android programming, so this may be an easy question: is the call to getSSID above similar to a system call in Unix? That is, if the device is stolen, how easy would it be for the thief to spoof the result of getSSID and trick my app into doing something it is not supposed to? – user1094206 Oct 28 '13 at 15:51
  • The SSID alone is definitely not enough, because your phone can be configured to log on to any open wifi. Then a thief would only need to create an open wifi with the same SSID as your network, the phone would auto-logon to it and the call to getSSID will report the same name as your home network. Anyboby with a router can do this within minutes. For a secure solution, you will need to digg much deeper and come from another perspective to this problem, not SSID, not MAC address of router, not anything replicable and receivable from a range of 100m from your home. – Daniel S. Oct 28 '13 at 16:42
  • I am not a security expert. You should post the question how to securely identify your home network in range as a separate question, maybe back on http://security.stackexchange.com . When you do, please link the other question here. – Daniel S. Oct 28 '13 at 16:55
1

you can get the SSID of the current wifi-connection with :

WifiManager mng = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
String currentSSID = mng.getConnectionInfo().getSSID();
Graya
  • 51
  • 4