• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps toggle wifi on/off when screen turns on/off

v1nsai

Member
I'm writing a simple app that will turn wifi on or off when the screen turns on or off, respectively. I tried registering <receiver> tags for SCREEN_ON and SCREEN_OFF Intents, then defining two BroadcastReceiver classes to catch the Intents, but nothing is happening. I think it's because the app isn't running when the screen turns on or off, which means I need a service running that can pass the Intents to the BroadcastReceivers, right?

Anyway, I'm having trouble figuring out how to connect the BroadcastReceivers to my service, how would I go about this?
 
Hi,
Good luck, i stumbled across the same issue. I'm trying to create an app that will allow me to configured settings like locale, but in a more flexible and dynamic way.

At the moment, its more for personal use than putting on the market.

Out of interest do you have any task-killer services running?

Its annoying that you can't really test such a scenario on the emulator.
 
If your still having trouble, I got it figured out. If you always want Intents to be passed to your BroadcastReceiver as long as your app is installed, then use <receiver> and <intent-filter> tags in the manifest. If you only want to receive intents under certain curcumstances, use a service that dynamically registers the intentfilter objects in onCreate, and remove them in onDestroy.

Hope that helps!
 
Hi,
Is this app complete now mate?... I really wanted to use it on my N1.. where i have to turn off and then turn on my wifi everytime i turn the screen on... if you app can do that automatically every time the screen turns on.. that would be great...
 
I'm still working on it, you can grab the source for it here

As of right now, the Wifi shuts off and turns back on no problem when screen turns on and off, but I'm working on getting the delays to work. Feel free to join the project!
 
I'm still working on it, you can grab the source for it here

As of right now, the Wifi shuts off and turns back on no problem when screen turns on and off, but I'm working on getting the delays to work. Feel free to join the project!

Great work. Just one question......why include the option for a delay? Why wouldn't you want WiFi to turn off and on right away?
 
Great work. Just one question......why include the option for a delay? Why wouldn't you want WiFi to turn off and on right away?

Its a matter of preference, really. The wifi will turn on the moment your screen turns on, even if your only checking the time real quick or something, i like a 5 second delay before wifi turns on. I like about a minute delay before it turns off, mainly to let my processes wrap up whatever they were doing, and if Im downloading something and accidentally let the screen turn off, I have a chance to catch it before I lose my connection
 
  • Like
Reactions: GIR
Yep, precisely what I did. All is working now, I need to update the google code repo when I get home.

Thanks for this app. You save me alot of battery! :rolleyes:

how can i start this app as service? I don't want to open this app manually every time that i reboot my device :)
 
Hello,
I just clocked this, what would need to be changed to do control the GPS in the same manner?

Regards,
Fred
 
Back
Top Bottom