I'm developing an Android app that intercepts the pressing hardware buttons and makes REST calls to their pressure. The button that I have to intercept is the Push to talk (PTT) button, so not a regular button, such as power button or volume button.
When the application runs in the foreground I use the method onKeyDown (int keyCode, KeyEvent event). The PTT button, as the identifier, has the number 27 and then inside the method I wrote the following lines of code:
if (keyCode == 27) {// I pressed the PTT button}
All this works perfectly.
But now I send the application in the background (with the function moveTaskToBack(true);) and when I press the PTT button I would intercept it.
I am aware of BroadcastReceiver, of IntentFilter and Service, however, these allow you to intercept the limited intent actions (such intent.action.SCREEN_OFF or others normal actions), among which are not able to find the pressure of the PTT button.
Is there any way to intercept the PTT button when the application is in the background?
Thank you
onKeyDown()
standpoint, they seem to be usingKEYCODE_CAMERA
, so maybeACTION_CAMERA_BUTTON
will work. – Rowney