I want to implement a service that disables the keyguard when connected to a certain WiFi network, and restores the keyguard when disconnected.
On my Galaxy Nexus (CM10) and HTC Desire (MIUI), I've tried the following solutions, but none have worked well:
- Tried using disableKeyguard() and reenableKeyguard() from inside the service. The problem is that it disables the keyguard at first, but when I open a different application and press home, I suddenly get the keyguard. After that, it doesn't work at all. Also, these functions are deprecated.
- I built a new activity which I start from inside my service using the new_task flag. I gave it one of the following to actions: showkeyguard and hidekeyguard. Accordingly I used getWindow().addFlags() to set FLAG_DISMISS_KEYGUARD or FLAG_SHOW_WHEN_LOCKED. The problem is the activity shows up and has to stay visible.
Can anyone suggest a method of doing this from a service? If the first solution is the only way to do it from the service, then I don't mind the deprecated stuff. What I want to know is why it's acting like that?
Thanks.