2

I need to override HOME key in my application. I've used code from this post but it's not working on android 4.X. Do you know other workarounds to achieve this task? I've looked a little bit in native Phone application (on android 2.2) but I couldn't find where is the code that overrides HOME button, but I've searched for text "TYPE_KEYGUARD" in all project and my ide couldn't find anything, which makes me think that there is another way to suppress HOME key. Any ideas?

Kara
  • 6,115
  • 16
  • 50
  • 57
Buda Gavril
  • 21,409
  • 40
  • 127
  • 196

1 Answers1

0

Post ICS i.e. Android 4+, the overriding of the HomeButton has been removed for security reasons, to enable the user exit in case the application turns out to be a malware.

Plus, it is not a really good practice to not let the user navigate away from the application. But, if your application requires so, what you can do is declare the activity as a Launcher , so that when the HomeButton is pressed it will simply restart your application and remain there itself (the users would notice nothing but a slight flicker in the screen).

EDIT #1 : Here is another workaround, more suited to your needs.

EDIT #2 : Just came across this. Haven't tested it. But looks kinda promising. Not sure if it would work, but you could give it a try.

Community
  • 1
  • 1
Swayam
  • 16,294
  • 14
  • 64
  • 102
  • I'm working on a VOIP application and on incoming call screen, this app needs to behave like the native one (ignore back, home key). – Buda Gavril Oct 30 '12 at 13:31
  • Then how will the user exit your app ? You cant really force the user to remain in your app. – Swayam Oct 30 '12 at 13:35
  • if the user answers the call or rejects it, or after the voicemail enters, the app will behave "normal" again – Buda Gavril Oct 30 '12 at 13:38
  • I guess you just declare it as a Launcher then. – Swayam Oct 30 '12 at 13:47
  • this can be a solution, but it will complicate the code and flows... I wanted to know if there is a straight forward way to implement this, but I see there is not... Thanks... – Buda Gavril Oct 30 '12 at 14:04
  • Well, in my opinion, declaring it as a launcher would be the easiest and the cleanest solution, without much additions in code. And no, there is no straight forward way to go about it. Glad that it helped you in any way. Good luck ahead! :) – Swayam Oct 30 '12 at 14:29