set Wifi Enabled via WifiManager - Android android.net.wifi

Android examples for android.net.wifi:Wifi Enable

Description

set Wifi Enabled via WifiManager

Demo Code

import android.content.Context;
import android.net.wifi.WifiManager;

public class Main {

  public static void setWifiEnabled(Context context, boolean enabled) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (enabled) {
      wifiManager.setWifiEnabled(true);//  ww  w.  j av  a 2  s.c o  m
    } else {
      wifiManager.setWifiEnabled(false);
    }
  }

}

Related Tutorials