0

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.

black
  • 781
  • 1
  • 7
  • 22
  • The reason method 1 wasn't working after the first trial is because I wasn't reenabling the keyguard. What I'm doing now is disabling keyguard on screen_on and reenabling it on screen_off. But I'm still facing the issue of keyguard reappearing when I press the home key (only once during each screen_on/screen_off cycle). – black Oct 19 '12 at 12:24
  • did you get this thing working? i'm facing some issues with Keyguard in a service also. – MarkySmarky Dec 11 '14 at 14:31
  • @MarkySmarky Questionably. I keep the keyguard enabled after the first screen_on. When the user dismisses the keyguard, Android braodcasts ACTION_USER_PRESENT. That's when I disable the keyguard and keep it disabled until I want to enable it again (not necessarily on screen_off). This only works on some devices. I would advise against doing anything to the keyguard to be honest. – black Dec 12 '14 at 15:09

1 Answers1

0

Have you tried disblekeyguard when service start, enablekeyguard when service destroy

sankun
  • 11
  • 2