1

I want to create an Android application that is opened in background when the power button is pressed twice.

I want to know how can I handle power button and choose what happens when user press power button?

Just as we have in Safety Apps which sends SOS messages on certain number of power key presses.

vhu
  • 12,244
  • 11
  • 38
  • 48

1 Answers1

0

First you need to add the following permission to your manifest file:

<uses-permission android:name="android.permission.PREVENT_POWER_KEY" />

It has two methods onKeyDown() and onKeyLongPress() @Override these two methods for performing some actions.

HassanUsman
  • 1,787
  • 1
  • 20
  • 38