-2

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.

4 Answers4

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
  • 84,451
  • 9
  • 82
  • 121
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,073
  • 146
  • 84
  • 117
Khizar Hayat
  • 3,049
  • 2
  • 16
  • 22
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
  • 33,034
  • 19
  • 115
  • 176
-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
  • 517
  • 1
  • 3
  • 4