1 minutes

Turn on and off Wi-Fi using Android API

By Editorial @stacktips, On Sep 17, 2023 Android 2.46K Views

Use the following code snippets to turn on and off wifi on Android devices.

public void toggleWiFi(boolean status) {
	WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
	if (status == true && !wifiManager.isWifiEnabled()) {
	} else if (status == false && wifiManager.isWifiEnabled()) {

For changing wifi state, you need the following permissions in your manifest file.

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


StackTips provides programming tutorials, how-to guides and code snippets on different programming languages.