Hello. I want to make sure that when logging into my application, the user disconnected wi-fi, or simply disconnected from the network.

Is this possible at all? I would be grateful for the information. And where can I read about the manipulations with the device through the application?

  • one
    If you want your application under any circumstances, even with the user's kick, to not work with Wi-Fi turned off, then most likely there is no way. The system can make the application believe in many strange things. - D-side

1 answer 1

  1. We drive into Google

android turn off wifi programmatically

  1. Follow the first link to en-SO

  2. We get the answer:

The following permissions are required in the manifest:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission> 

To enable / disable Wi-Fi, you can use this code (in the activation class):

 WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(true); wifiManager.setWifiEnabled(false); 

And this is where you can check whether it is enabled or not:

 boolean wifiEnabled = wifiManager.isWifiEnabled() 
  • one
    Well, they do not learn this English in order to surf normally on search engines .. ( - E1mir
  • one
    @KryTer_NexT, it’s also possible that the inability to form a relevant request is the case) Or they drive it into Yandex - it processes such requests badly. - JuriySPb