How to hook into the Power button in app?

How to hook into the Power button in app?

android.permission.PREVENT_POWER_KEY code is not working.


Welcome to the Samsung Developer Community.

Can you please share the code snippet to reproduce your issue?
In which Samsung phone it’s not working? What is the expected behavior and what is happening now?

Please share your query in detail so that we can assist you accordingly.

Thank you,

test main class sample code

keyCode == KeyEvent.KEYCODE_POWER line not working to debug.

//test device a82 model

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ) {
     //event working

    if (keyCode == KeyEvent.KEYCODE_POWER ) {
    //event not working

    return super.onKeyDown(keyCode, event);