6

I am trying to detect when power button is pressed in BroadcastReceiver class, Actually I am implementing it when Device Administrator Permission is activated. I have google so much but not able to find it.

In broadcast receiver class, when screen is ON and OFF then I am detecting it using this method

if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) 
        {
          Log.v("Screen Off", "Screen OFF");

        }

        else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) 
        {
          Log.v("Screen ON", "Screen ON");
               }

But I have to detect when power button is pressed only. One thing, I want to make it clear there are many application which is performing this functionality, for example: https://play.google.com/store/apps/details?id=com.startv.gumrah .This is many using for SOS application like

an emergency App that, at the click of the power button of your smartphone 2 times consecutively begins sending out alert messages

Please help me how to detect when we press power button.

10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.