Hello all..
This is a simple code snippet to enable WI-FI in android programatically in android.

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;
}

Note : Make sure to add the permissions in the manifest file.
These are the permissions.

  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

Please leave your valuable comments on this post.

 

Leave a Reply

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

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.