0

I would like to know if anyone has accurate answer on how to disable power button in android phone? I did research and all codes are not working. Still failed. and here is my latest code that didn't work because I guess on our current android version. Does anyone know?

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_POWER) {
        // Do something here...
        event.startTracking(); // Needed to track long presses
       
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

and

@Override
    public boolean onKeyLongPress(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            // Do something here...
            InsertData3(EmpID,"Backpress",Date_log);
            return true;
        }
        return super.onKeyLongPress(keyCode, event);
    }
a_local_nobody
  • 7,947
  • 5
  • 29
  • 51

0 Answers0