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.
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.
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