【发布时间】:2011-08-09 18:43:37
【问题描述】:
我正在尝试找到一种方法来检测用户何时在我的服务在后台运行时以任何方式触摸屏幕。例如,我希望能够检测用户何时按下主屏幕上的应用程序图标。这可能吗?如果可以,如何实施?
【问题讨论】:
-
可能会派上用场:Detect touches from a service
标签: android service background touch screen
我正在尝试找到一种方法来检测用户何时在我的服务在后台运行时以任何方式触摸屏幕。例如,我希望能够检测用户何时按下主屏幕上的应用程序图标。这可能吗?如果可以,如何实施?
【问题讨论】:
标签: android service background touch screen
请看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.
}
【讨论】: