Search code examples
androidandroid-serviceandroid-wifi

How to disable Wifi when not used in background android?


I want to disable the wifi when not connect to any network. It will be running in the background and disabled anytime when wifi are enable and not used. How can I do that? Please give me some advice. I have to use Foreground or Service/ Broadcast Receiver.


Solution

  • You may be interested in Tasker. It can automate basically every setting in Android.

    You can make a profile State> Variable Value> %WIFI=on Action: If "Wifi Info" %WIFII !contains "CONNECTION" then Net> Toggle Wifi> Off

    You can also do this in Java with a bit more work. I can provide details on that if you request.

    And also if you're lazy you can download neat little apps that take care of it for you: Auto Wifi Off

    Hope that helps