0

I want to detect home key press three times from home screen of android such as after this want to perform event. Is there any way to detect home key press three times in android.

Ajay S
  • 48,003
  • 27
  • 91
  • 111

3 Answers3

3

You have to this in the Android OS, PhoneWindowManager, this is where the HOME button is handled.

Specificly: http://androidxref.com/4.1.1/xref/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java#1761

To change that you have to change and build the AOSP. And flash this on you device. Therefore for app developers this is not possible.

RvdK
  • 19,580
  • 4
  • 64
  • 107
1

If homekey is pressed in the activity it will come to

@Override
    protected void onUserLeaveHint() {
        // TODO Auto-generated method stub
        super.onUserLeaveHint();
    }

put the counter and when it reached to 3 perform the action.

Dinesh Prajapati
  • 9,274
  • 5
  • 30
  • 47
0

To handle key event you have to override the methods onKeyDown() and onKeyUp().

see this link will guide you just you have to add your logic.

Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85