Saturday, 14 July 2012

Enable/Disable WiFi in Android Programatically

How to Enable/Disable WiFi  Programatically in Android.(Android WiFi API)

In Android using WifiManger Class we can find WiFi state and we can Enable/Disable WiFi.

To Enable WiFi

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(true);

To Disable WiFi


WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(false);

Note: To access with WiFi state, we have to add following permissions inside the AndroidManifest.xml file:

android.permission.ACCESS_WIFI_STATE
android.permission.UPDATE_DEVICE_STATS
android.permission.CHANGE_WIFI_STATE

For More Information about WifiManager Android Developers

No comments:

Post a Comment

Android SQLite Database Viewer or Debuging with Stetho

Every Android Developer uses SQLite Database to store data into the Android Application data. But to view the data in SQLite have a lot of...