12

In Honeycomb I was able to create a system overlay with TYPE_SYSTEM_OVERLAY and receive touches with FLAG_WATCH_OUTSIDE_TOUCH.

Now ICS has changed something. I can still create the system overlay, but i can't get touches.

Now, i am able to create the same with TYPE_SYSTEM_ALERT and get touches, but it just catches the touchevents, and not passing them on like in Honeycomb.

Any idea's?

Kind regards

TZHX
  • 5,291
  • 15
  • 47
  • 56
Edwin Schriek
  • 157
  • 1
  • 2
  • 12

2 Answers2

24

To create an overlay view, when setting up the LayoutParams DON'T set the type to TYPE_SYSTEM_OVERLAY.

Instead set it to TYPE_PHONE.

Use the following flags:

FLAG_NOT_TOUCH_MODAL

FLAG_WATCH_OUTSIDE_TOUCH

FLAG_NOT_TOUCH_MODAL << I found this one to be quite important. Without it, focus is given to the overlay and soft-key (home, menu, etc.) presses are not passed to the activity below.

jawsware
  • 924
  • 6
  • 13
  • 4
    FYI jawsware has a full sample app here that works for ICS: http://www.jawsware.mobi/code_OverlayView/ – Chris Lacy Jan 04 '13 at 01:58
  • 3
    Not able to catch click events on any of the veiws in it on 4.2.X, though works well on lower versions of Android. Any suggestions? – Kamran Ahmed Jun 01 '13 at 05:30
  • Thanks. It worked for me - I had 'TYPE_SYSTEM_OVERLAY' and I changed it to 'TYPE_PHONE' with 'FLAG_NOT_TOUCH_MODAL' and set listener with 'setOnTouchListener' instead of 'setOnClickListener' to receive touches in a PopUp windows above my activity as well as in the activity below. In my case it was a default system incoming call notification with an overlaying window. – kosiara - Bartosz Kosarzycki Aug 12 '15 at 13:47
  • @kosiara, were you able to prevent Home Button click? – 5er Nov 02 '15 at 00:47
  • @jawsware, do you know maybe how to prevent Home Button click? – 5er Nov 02 '15 at 00:48
  • @jawsware , TNX! I was needed only fact of touch - true\false. Now it WORKS ! – Inoy Apr 03 '16 at 22:54
7

Everything you describe is true. It is presumably to tighten up security, as the former behavior was the source of tapjacking attacks. I wrote a blog post recently about this change.

Any idea's?

Don't use either of them.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I just found a app that still does it in ICS, Swipepad. It allows to drag in every app from a pre-defined point to to the middle of the screen and then start a overlay, so there must be a way – Edwin Schriek Mar 11 '12 at 15:33
  • @EdwinSchriek: That behavior sounds consistent with `TYPE_SYSTEM_ALERT` -- it seems reasonable that continuous touch events started via a tap on a system alert would be delivered to that system alert and not an underlying app. – CommonsWare Mar 11 '12 at 15:37
  • hmm, i guess it's not possible then, but i will keep looking. Thanks! – Edwin Schriek Mar 11 '12 at 15:50
  • @Edwin Schriek, Can you help me to solve my question?https://stackoverflow.com/questions/65405516/touch-event-getaction-does-not-work-under-service-class-in-android-studio – Mohsen Ali Dec 28 '20 at 11:26