I'd like to understand if there's a way to trigger the power menu, as if the user had long-pressed the power button. I can be root / a system app, so normal security restrictions may not apply.
What I'm trying to do is prevent the screen from sleeping when power is pressed, but keep the long-press power menu. I was able to keep into the PREVENT_POWER_KEY
permission, which allows you to catch the key event KEYCODE_POWER
, but is also completely disables the normal power button behavior. That leads me to the original question: how to manually trigger the Android power menu.
I was able to track this down in the Android source: GlobalActions.java
. if I'm reading things correctly, it looks like this code programmatically creates a GlobalActionsDialog
. This class is not public. My assumption here is that I'm out of luck, but just checking if someone knows a workaround.
I appreciate one would not normally want to do this, but it is for a custom device + ROM.