override Home key in android ICS

喜欢而已 提交于 2019-12-03 18:07:46

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/13139970/override-home-key-in-android-ics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!