Skip to content Skip to sidebar Skip to footer

Listen For DispatchKeyEvent Whilst App Is In The Background

The application I'm writing must listen for a physical hardware button click event from outside of my app. My device has a dedicated SOS button that I'm trying to use. Up to now I

Solution 1:

I can't comment yet as I do not have 50 reputations, so apologies for the added string here. So I am also working on this and I can share what I have done.

Firstly we looked at the Generic.kl and other keylayout files that are found in the /system/usr/keylayout folders. We can easily change the behaviour of any button in here but of course you are restricted to only the main system commands like CAMERA, VOLUME_UP, SEARCH etc.

So you can't run an app directly from here.

So we turned to the init.rc file you can find by cracking open the boot.img on the main ROM. There's a great thread here about this:

Running app from button press

So we added a script in the /system/bin folder. I checked the script runs by running it manually in the shell. I also tested with a basic echo script.

We then added the service in the init.rc file but it did not work. In fact we tried to change the button listened for and nothing worked. Very frustrating as there are services written in here by Android exactly the same. We made sure that we removed all references to the buttons in the .kl files too, just in case they overrode the init.rc service.

So the service in the init.rc file must be the culprit, but not sure why yet. So still stuck, very close, but so far away!!


Post a Comment for "Listen For DispatchKeyEvent Whilst App Is In The Background"