I want to know whether we can make an android app which works only when we connect to a specific wi-fi Network? All help is much appreciated! I'm all out of ideas here. Thank you.
Asked
Active
Viewed 100 times
4 Answers
1
boolean onRightNetwork() {
WifiManager wifiManager = (WifiManager) App.getContext()
.getSystemService(App.getContext().WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
return wifiInfo.getSSID().equals(NETWORK_NAME);
}
Run that in onResume, and just pop up a screen that says to connect to the right network if it returns false. You may also want to register a broadcast receiver to listen for wifi connect/disconnect events and perform this check as needed there as well.

Gabe Sechan
- 90,003
- 9
- 87
- 127
-
i have a doubt! what if in future the SSID is changed? then don't we have to give another update just for a small change. – Deepak Vardhan Feb 17 '18 at 15:46
0
Try this:
WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
wifiInfo.getSSID();
After getting the SSID, match it with your desired one. If the condition is met, then do whatever you want.

Pang
- 9,564
- 146
- 81
- 122

Khizar Hayat
- 3,427
- 3
- 18
- 22
-
Mac address isn't what you want here, that identifies a router not a network – Gabe Sechan Mar 01 '16 at 12:42
-
Use SSID. That should identify the network. So you were on the right track. – Gabe Sechan Mar 01 '16 at 12:47
0
You can write your own logic for that in launcher Activity
.
WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
String name = wifiInfo.getSSID();
above code is to get name of currently connected network name, you can make condition if it matches your predefined name, allow user to use your application.

Ravi
- 34,851
- 21
- 122
- 183
-1
You could try something like this:
ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (!mWifi.isConnected()) {
// exit app here
}
make sure You have proper permission in Your AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
Related answer here: https://stackoverflow.com/a/3841407/3693617

Community
- 1
- 1

Artur Boruński
- 527
- 1
- 3
- 4