5

Is it possible to detect touch events from within another application, specifically swipes? I'd like to be able to detect if the user has swiped left or right (even with 2 fingers - but not required). Perhaps there is a service or broadcast I can listen to.

or failing that, is there some API perhaps that I can poll say 10 times a second to get the touch state and I can compute the rest (why, I remember writing a mouse driver strobing the COM1 port with IN OUTs in 8086 assembler coded in a TSR on a XT...)!

Anyway, any help appreciated. (I think it could be done by hijacking the primary Launcher and having a transparent click-through on-top activity, but that's seriously fraud with danger!)

Jon
  • 812
  • 2
  • 11
  • 18
  • What's your use case for wanting to do this? – Rich Schuler Jan 08 '11 at 12:55
  • Sorry, missed this comment. Was intending to write a task switcher. A 2 finger gesture swipe left to switch to the previous app, to the right for the next app, a swipe down to get to Home/desktop, and up for, maybe silent mode on or off - I'd make them configurable. To my mind, holding the Home key down for the "alt-tab" is tiresome, I wanted to provide another option. Also a 2 finger swipe is pretty much unemployed by all apps (at best they pinch or expand with 2 fingers, not swipe). – Jon Jan 08 '11 at 21:51

1 Answers1

2

Is it possible to detect touch events from within another application, specifically swipes?

Fortunately, no.

or failing that, is there some API perhaps that I can poll say 10 times a second to get the touch state and I can compute the rest

Fortunately, no.

I think it could be done by hijacking the primary Launcher and having a transparent click-through on-top activity

Fortunately, no.

You are welcome to write your own home screen application, in which case you can track your own touch events on your own home screen. You are welcome to write an ordinary application and track your own touch events on your own activities.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    I know it can be done, and that's based on the fact it's already been done: - http://www.appbrain.com/app/smart-taskbar-(sidebar)/com.smart.taskbar Perhaps he API'd it in native Android code and not Java, but I think its a inbetween layer, OS to launcher, that he's intercepted. Thanks for your response :) – Jon Jan 08 '11 at 19:35
  • 1
    @Jonathan: Whatever technique that app is using represents a security flaw. Thank you for pointing it out, so we can work to correct the flaw, so apps cannot intercept gesture-based passcodes and the like. – CommonsWare Jan 08 '11 at 20:07
  • What he has done is created a small Stay-on-top window. I'm sure it's from intercepting the launcher. So he isn't reading other apps events, but its the onTouch of his own app. I also believe in security and am happy if I can't do this myself for the sake of security. I went looking for why I thought it was the launcher and found Sebastian Roth's comment here http://stackoverflow.com/questions/4291349/how-to-make-an-activity-window-stay-always-on-top . Hope that helps in eliminating any kind of threat. – Jon Jan 08 '11 at 21:28
  • I remember that app and used it for a bit when it came out. I'm pretty sure it's done by creating a PopupWindow and continually forcing it to be on top. A PopupWindow will allow you to get any outside touch events and react however you want to them. IIRC it did not replace the launcher. – Rich Schuler Jan 09 '11 at 02:07
  • Ah righto, makes sense. I think a Toast can behave a bit like that too. I think I'll take this answer as correct, as from what I've read here, I don't really want it answered so it doesn't get abused - just in case there is a real answer that gets the baddies thinking!! – Jon Jan 09 '11 at 06:22