2011-08-09 53 views
2

我想找到一种方法来检测当用户在后台运行服务时以任何方式触摸屏幕。例如,我希望能够检测用户何时按下主屏幕上的应用程序图标。这是可能的,如果是的话,它将如何实施?Android:检测服务的触摸

+0

可能会派上用场:检测从服务接触(http://stackoverflow.com/questions/4481226/creating-a-系统叠加总是在最顶部按钮功能于机器人) –

回答

1

请参阅this服务说明。您应该可以使用Messenger将消息发送到您的服务。所以,在你的onClick事件,你会打电话给你的使者......例如:

 try { 
      Message msg = Message.obtain(null, 
        MessengerService.MSG_BUTTON_CLICKED); 
      msg.replyTo = mMessenger; 
      mService.send(msg); 

      // Give it some value as an example. 
      msg = Message.obtain(null, 
        MessengerService.MSG_SET_VALUE, this.hashCode(), 0); 
      mService.send(msg); 
     } catch (RemoteException e) { 
      // In this case the service has crashed before we could even 
      // do anything with it; we can count on soon being 
      // disconnected (and then reconnected if it can be restarted) 
      // so there is no need to do anything here. 
     }