Android - How to enable and disable the wifi

0

I have a java app with two buttons. How to do when to press the first the wifi to be activated, and when to press the second it to be disabled?

Thank you.

    
asked by anonymous 04.09.2016 / 20:46

1 answer

3

You can use the WifiManager class and through the setWifiEnabled method you can enable and disable wifi, official documentation can be found here .

For this you must add the permission in the manifest of your application.

In your AndroidManifest.xml add the following permission:

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

and in your program implement:

   WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
   wifi.setWifiEnabled(false); //desabilita
   wifi.setWifiEnabled(true); //habilita
    
04.09.2016 / 21:32