覆盖安卓ICS Home键ICS、Home

2023-09-12 08:13:57 作者:海绵宝宝╰永远的幸福

我需要重写HOME键在我的应用程序。我用code从这个帖子但它不工作在Android 4.X.你知道其他方法来实现这一任务呢?我在所有的项目和我的IDE看着机应用程序(在Android 2.2)一点点,但我找不到在哪里code重写HOME键,但我已经搜索文本TYPE_KEYGUARD找不到任何东西,这让我觉得有另一种方式来燮preSS HOME键。任何想法?

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?

推荐答案

邮政ICS即安卓4+,在为homeButton的首要已被删除出于安全原因,以使在案件中的应用原来是一个用户出口恶意软件。

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.

另外,它并不是一个非常好的做法,不能让用户导航离开该应用程序。但是,如果你的应用需要的话,你可以做的就是申报活动为启动,这样,当为homeButton为pressed将只需重新启动您的应用程序,并保持有本身(用户会发现只是轻微的闪烁在屏幕)。

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).

编辑#1:以下是另一种解决方法,更适合您的需求。

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

编辑#2:只是碰到的这一点。没有测试过。但看起来有点前途。不知道是否会工作,但你可以试试看。

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.

 
精彩推荐