-3

I want to send a SOS message using my own mobile application by clicking the power button N times

ZachB
  • 13,051
  • 4
  • 61
  • 89
  • 1
    Please provide more information, what have you tried, research, ... this is way too broad. I would guess this will have to be in a background service to be able to stay up during your events. You can't prevent the power event to be consumed by the OS. – AxelH Dec 28 '17 at 11:59

2 Answers2

0
  int counter = 0;
  public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
            // do what you want with the power button
            counter++;
            if (counter==3){
                //Do your thing
                counter=0;
            }
        }
        return super.onKeyDown(keyCode, event);
    }
  • Yea in that case you will definitely need to implement service that will keep running when app is killed. Didn't go that deep he just asked how to detect 3 clicks on power button –  Dec 28 '17 at 12:11
  • yea.. he have to use service for this. – Nikhil Borad Dec 28 '17 at 12:13
0

First Asking for system permission to draw overlay

after that Starting a service and adds a special view to WindowManager

reference: Detect power button long press

Hope it helps..

Nikhil Borad
  • 2,065
  • 16
  • 20