7

How do I get touch events like you can from an Activity using public boolean onTouchEvent(MotionEvent event)? There obviously isn't an onTouchEvent method to override in a service, so how can I go about doing this? Is there a direct way or a reliable work-around?

My idea is to create a service that listens in the background for the user to make a certain gesture, then do something when that user has made the correct gesture. Thank you!

EDIT: This question is intended for the answer to this question.

Community
  • 1
  • 1
Brian
  • 7,955
  • 16
  • 66
  • 107
  • I don't know 100% so I'm not going to put this in the answers, but the whole idea of a Service is there isn't any human interaction. I would also think that 9 times out of 10 anybody who would be using the phone would not be doing gestures outside an app, so any solution may bring up a handler that could slow down overall user experience. – DeeV Jul 27 '11 at 15:51
  • Well take a look at these two apps https://market.android.com/details?id=mobi.conduction.swipepad.android&feature=search_result and https://market.android.com/details?id=com.mobilemerit.wavelauncher&feature=search_result. I'm trying to figure out how to do that. – Brian Jul 27 '11 at 17:46
  • Then I hope someone answer this because I'd be interested in knowing too. Although, I *think* those are custom widgets like those found on the desktop of the phone only they're always on top. If I remember right, the Wave Launcher starts out off-screen and you have to drag it up. The bottom 20 pixels or so was the edge of the widget that recorded it being touched. From the looks of it, the swipe pad is the same way. Neither use a service. – DeeV Jul 27 '11 at 19:07
  • No I think you're mistaken, both of them DO use services. If you run them and go to settings, you can see that both run as a service. Take a look at this question: http://stackoverflow.com/questions/4481226/creating-a-system-overlay-always-on-top-button-in-android – Brian Jul 28 '11 at 17:50
  • Oh, well then. That's what I didn't fully answer. Good to know this is possible. – DeeV Jul 28 '11 at 18:36

1 Answers1

0

You can create a 0x0 view and add it to the Service's window as a system dialogue that is always on top.

You can listen to events using the 'WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH' permission. Unfortunately, you can only get the initial touch event and you can not pass on the event to lower activities. I am glad you can not do that actually; can you imagine how malware would exploit this to obtain user's credentials.

Gallal
  • 4,267
  • 6
  • 38
  • 61
  • Thanks but if you refer to my question, I have a link to a question that shows just how that would work. My biggest issue is actually getting the moving touch gestures. Apps like Wave Launcher and SwipePad are able to do this, but I just don't know how. – Brian Jul 29 '11 at 08:35