simple code snippet to enable WI-FI in android programatically in android.
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE">
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE">
public boolean enableWIFI() { WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); if(wifiManager.isWifiEnabled()) { if(wifiManager.setWifiEnabled(false)) return true; } else { if(wifiManager.setWifiEnabled(true)) return true; } return false; }Make sure that you add the permissions:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE">
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE">
Comments
Post a Comment