简体   繁体   English

覆盖服务中的主页按钮和后退按钮-Android

[英]Override Home Button and Back Button in Service - Android

I need to detect HomeButton event in Service. 我需要在服务中检测HomeButton事件。 Not in Activity. 不在活动中。

I am making an app which will make overlay on any other App. 我正在制作一个可以在其他任何应用上叠加的应用。 Like additional menu which is always on top of the screen. 就像其他菜单始终位于屏幕顶部。 In some specific events I need to override pressing home button, menu button, back button, volume button also power button. 在某些特定事件中,我需要覆盖按下主页按钮,菜单按钮,后退按钮,音量按钮以及电源按钮。

I believe that this must be done in Service, since all other Apps must run normal. 我相信这必须在Service中完成,因为所有其他Apps必须正常运行。 So the events must be handled in Service not in Activity. 因此,必须在服务而不是活动中处理事件。

It is possible: http://www.kidscrape.com 有可能: http : //www.kidscrape.com

You might want to find a way how to communicate from the Activity to the Service (and conversely). 您可能想找到一种方法,如何从ActivityService (以及相反)进行通信。 The easiest would be to use EventBus , either on of these two: 最简单的方法是使用EventBus ,这两种方法之一:

  1. http://square.github.io/otto/ http://square.github.io/otto/
  2. https://github.com/greenrobot/EventBus https://github.com/greenrobot/EventBus

So ultimately you just fire an event from Activity#onBackPressed() and catch it in the Service . 因此,最终您只需从Activity#onBackPressed()触发一个事件并将其捕获到Service

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM