Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable/disable WiFi from an application?

I want to enable/disable wifi from my Android application. How can I do that?

like image 778
Mustafa İrer Avatar asked Apr 15 '11 08:04

Mustafa İrer


People also ask

How do I turn off Wi-Fi for certain apps?

To access this, go to “Settings -> Network & Internet” and select the Wi-Fi network. In some phones, it can be viewed as an icon. The data saver menu has a toggle switch which remains off. As soon as you turn it on, you will see a list of apps with Internet access that can be controlled.

How do I enable a disabled WiFi network?

Go to settings, then on Wireless and Network check to ensure that the WiFi icon is turned on. Alternatively, draw down the notification bar menu, then enable WiFi icon if it's off. Many users have reported having fixed android wifi problem by simply disabling airplane mode.

Can you prevent an app from using Wi-Fi?

In the Android Mobile network settings, tap on Data usage. Next, tap on Network access. Now you see a list of all your installed apps and checkmarks for their access to mobile data and Wi-Fi. To block an app from accessing the internet, uncheck both boxes next to its name.


1 Answers

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifi.setWifiEnabled(false); // true or false to activate/deactivate wifi 

You also need to request the permission in your AndroidManifest.xml :

<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> 
like image 78
Codii Avatar answered Oct 09 '22 05:10

Codii