I would like to execute some code when user presses one of hardware buttons(it doesn't matter, which of these, but Power is preferrable).
I would like to catch events even application is minimized to background and device is sleeping. (Primary task is processing events, when device is inside pocket and the user presses button three times in a row, but not takes out the device).
Is that possible? If it isnt't possible for power button, may be it's possible for volume or home buttons? How can I do it?
I tried many ways, but the only worked is that:
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
BroadcastReceiver mReceiver = new ScreenReceiver();
registerReceiver(mReceiver, filter);
But I can't process triple press because of huge delay between actual button press and receiver's code execution.