Android Overlay to Grab All Touch, and Pass Them On

Android overlay to grab ALL touch, and pass them on?

Found this documentation that pretty much states that it's not possible to do both:
Android : Multi touch and TYPE_SYSTEM_OVERLAY

They discuss workarounds but I don't think any of them will actually work for exactly what I'm trying to do. Both given the events to the underlying app, and being able to snoop them to act upon them for myself.

To create an overlay view, when setting up the LayoutParams you need
to set the type to TYPE_SYSTEM_OVERLAY and use the flag
FLAG_WATCH_OUTSIDE_TOUCH. This presents a problem because as the
Android documentation states: "you will not receive the full
down/move/up gesture, only the location of the first down as an
ACTION_OUTSIDE." In order to receive the full array of touch events
you need to use the TYPE_SYSTEM_ALERT type, but this causes the
overlay to take over the screen and stop interaction with other
elements.

Anyone wants to disagree I'd love to hear good news :-D

Detecting touch events in overlay and passing them further

Fortunately, this is not possible, except perhaps on rooted devices or via custom firmware.

What you are describing is a tapjacking attack: spying on user input while passing that same input along so it has normal effects. This has been blocked for privacy and security reasons since Android 4.0.

How to make overlay receive touch events without consuming the touch for the other apps?

Please Remove this flag

WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE 

with this flag

WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE

see this link https://medium.com/@kevalpatel2106/create-chat-heads-like-facebook-messenger-32f7f1a62064

How to create an overlay that blocks touch events to UI below it?

Following code will add overlay on top of everything :

View v1 = new View(this);    
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
1000,
50,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.OPAQUE);

params.gravity = Gravity.BOTTOM;
WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
wm.addView(v1, params);

to block the touch event either you have to change the flag or below code will work:

protected boolean onTouchEvent (MotionEvent me) {
return true;
}

For v1 you would do an import:

import android.view.View.OnTouchListener;

Then set the onTouchListener:

v1.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
})


Related Topics



Leave a reply



Submit