2

I am trying to find a way to detect when a user touches the screen in any way while my services is running in the background. For example, I want to be able to detect when a user presses on an app icon on the home screen. Is this possible and if so how would it be implemented?

Joshua Abrams
  • 377
  • 1
  • 4
  • 16
  • Might come in handy: [Detect touches from a service](http://stackoverflow.com/questions/4481226/creating-a-system-overlay-always-on-top-button-in-android) – Kamran Ahmed May 31 '13 at 07:05

1 Answers1

1

Please see this explanation of services. You should be able to send a message to your service using a Messenger. So on your onClick event you will call your messenger ... example:

        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.
        }
Jack
  • 8,921
  • 4
  • 44
  • 73