I need to develop a lockscreen application. I've already set up the Foreground service including a Broadcast receiver that listens to Screen-Off events.
Now I am stuck with the home button. I know there are several lock screen apps on Google Play Store, and they work. When the virtual home button is pressed, it shows that it is pressed, but nothing happens.
I already looked around and tried a few things:
- Using TYPE_KEYGUARD does not work (deprecated)
- Trying to catch the home button click with OnKeyDown does also not do anything
- Trying to overlay a dialog to lock the activity results in the following error:
Unable to add window android.view.ViewRootImpl$W@e68931b -- permission denied for window type 2010
(even though I set the android.permission.SYSTEM_ALERT_WINDOW in my manifest).
- I also tried using a lock task (screen pinning). It works, but it shows a message that the lock can be disabled when holding the back and the recent button.
Is there a way so that the lock task can only be deactivated from the app itself? How do the lockscreen apps in the Play Store lock the home button press?
Figured it out myself. The Lockscreen Apps in the App Store do not disable the home button. They indeed use a system overlay window, hiding the home screen even when the button is pressed. The error resulted as I tried to use TYPE_SYSTEM_ERROR for the overlay. For newer API versions, TYPE_APPLICATION_OVERLAY works