10

I know that services cannot implement Back key press and I understand the rationale. But there is an app called SideBar (on Play Store) that reacts to back key presses. It is a service that adds a view as system overlay and removes the view when the back key is pressed. Can anybody explain how this is done?

Here is another app that does it well. I have scoured the web, but have not found a solution to this problem. Any ideas?

4

2 回答 2

0

它可能是使用系统警报窗口完成的 - 因此该服务创建并管理一个添加到窗口管理器的窗口,该窗口管理器上设置了自定义回调

于 2013-09-09T10:47:12.547 回答
-2

是在服务中添加视图的好例子,如果你想在服务中使用监听器,你也可以使用。

我也在寻找服务中的监听器实现,终于找到了。

记得添加权限

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

并添加您的服务类

<application>
.
 .
  <service android:name=".YourServiceClass"></service>
 .
.
</application>

在 AndroidManifest.xml 中。

于 2014-04-28T19:31:46.780 回答