--ADVERTISEMENT--

In this tutorial, you will learn to ON/OFF or Enable/Disable WIFI connection programmatically from your android application. It’s easy to on and off wifi in android and here I have used toggle button too. If you click on the toggle button WIFI connection will be enabled/on and again if you click on the same toggle button WIFI will be disabled/off.

We have use Connectivity Manager class to make android application working with wifi. To turn on and off wifi programmatically in android you have to add following permission in your AndroidManifest.xml file.


Following is the code to enable and disable (ON/OFF) wifi programmatically in android.

Related:
How to Get the Phone Number Programmatically in Android
Check Internet Connection in Android
Android Switch Button Example

How to Turn ON and OFF WiFi Connection Programmatically in Android


XML Layout File


res/layout/turn_on_off_wifi_programmatically.xml

Java Activity File


src/EnableDisableWIFI.java

Strings.xml File


res/values/strings.xml


How to Turn ON and OFF WiFi Connection Programmatically in Android

That’s all. Now, run your Turn ON and OFF WiFi Connection Programmatically in Android application, make sure that you have to add above permission in AndroidManifest.xml file.

Post a Comment

Powered by Blogger.