Java tutorial
//package com.java2s; import android.content.Context; import android.net.wifi.WifiManager; public class Main { static public Boolean toggleWifi(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); return toggleWifi(wifiManager, wifiManager.isWifiEnabled()); } static public Boolean toggleWifi(Context context, Boolean enable) { return toggleWifi((WifiManager) context.getSystemService(Context.WIFI_SERVICE), enable); } static public Boolean toggleWifi(WifiManager wifiManager, Boolean enable) { wifiManager.setWifiEnabled(enable); return wifiManager.isWifiEnabled(); } }