How to enable or disable Wifi in android programmatically

In this post, we will see how to enable or disable Wifi in android programmatically.
It is very simple to enable or disable wifi from android code.
For enabling WiFi:
For disabling Wifi:
So you can enable or disable WiFi using WifiManger class.
You need to add extra permissions in AndroidManifest.xml to enable or disable Wifi.

Source code:

Step 1 :

Create an android application project named “EnableDisableWiFiApp”.

Step 2:

Add following permissions in AndoridManifest.xml.

💻 Awesome Tech Resources:
  • Looking for ⚒️ tech jobs? Go to our job portal.
  • Looking for tech events? Go to tech events 🗓️ Calendar.️

Go to app -> src -> main -> AndroidManifest.xml and add above permissions. AndroidManifest.xml will look like below xml.

Step 3 :

Change res ->layout -> activity_main.xml as below:

Step 4:

Change src/main/packageName/ as below:

Step 5:

Run the app
When you run the app, you will get below screen:

When you click on toggle button, you will get below screen:

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.