我正在尝试找到一种方法,以便在我的服务在后台运行时检测用户何时以任何方式触摸屏幕。例如,我希望能够检测用户何时按下主屏幕上的应用程序图标。这是可能的,如果是这样,它将如何实施?
答案 0 :(得分: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.
}