I would like to know how could i block the dial, home , back and the end call button on an android device.
I know this is possible because there is an application : TheftAware which does block all the buttons so they have no effect at all.
And I also would like to know how to make a dialog window or any kind of window which would stay on top no matter what (this is also done in theftaware).
They are also able to block(hide) the call screen… does someone know how are they doing that ?
Note: Does all this means that android is not that secure after all ?
I just wanted to clear up a few bits of information here.
The code example from BeRecursive is incorrect in a few ways. As already noted, it won’t block the Home button, but it has other problems:
In order to consume the event so the
rest of the Android framework won’t
act upon it, you need to return
truefrom theonKeyDownhandler,not
false. The contract is thattruemeans the application handledthe event and the framework should
not perform the default key event
handling. (Praveen’s code example also has the same issue).
Starting from Android 1.5 and later,
the Android framework moved the
action activation from
onKeyDownto
onKeyUp. So you’ll also needto implement the blocking in the
onKeyUphandler, not just theonKeyDownhandler.It is possible to block the
KeyEvent.KEYCODE_CALLbutton usingthis technique, but not the
KeyEvent.KEYCODE_ENDCALLbutton.This appears to be for security
reasons.
Finally, the trick of setting
WindowManager.LayoutParams.TYPE_SYSTEM_ALERTdidn’t have any effect for me in terms of actually blocking any of the hardware buttons. It might be useful for supressing popups from other applications, but I haven’t explored this fully.There’s lots of good information from the Android team in this blog post.