Android:从服务中检测触摸
我试图找到一种方法来检测当我的服务在后台运行时,用户以任何方式触摸屏幕。例如,我希望能够检测用户何时按下主屏幕上的应用程序图标。这可能吗?如果可能,将如何实施?请参阅服务说明。您应该能够使用Messenger向您的服务发送消息。所以在你的onClick活动中,你将呼叫你的messenger。。。例如:Android:从服务中检测触摸,android,service,background,touch,screen,Android,Service,Background,Touch,Screen,我试图找到一种方法来检测当我的服务在后台运行时,用户以任何方式触摸屏幕。例如,我希望能够检测用户何时按下主屏幕上的应用程序图标。这可能吗?如果可能,将如何实施?请参阅服务说明。您应该能够使用Messenger向您的服务发送消息。所以在你的onClick活动中,你将呼叫你的messenger。。。例如: try { Message msg = Message.obtain(null, MessengerService.
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.
}
可能会派上用场: