Reputation: 1
I have one ActivityMonitor class and in which I have attachTouchDetectorView() methos as below:
private void attachTouchDetectorView(Activity activity) {
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(0, 0, 0, 0, TYPE_APPLICATION, FLAG_NOT_FOCUSABLE|FLAG_NOT_TOUCH_MODAL|FLAG_WATCH_OUTSIDE_TOUCH, TRANSLUCENT);
WindowManager windowManager = activity.getWindowManager();
View view = new View(activity);
//set listener
view.setOnTouchListener(new TouchNotifier());
windowManager.addView(view, layoutParams);
}
This method creates a view and set touch listener TouchNotifier as below:
private class TouchNotifier implements View.OnTouchListener {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
// do your task
// Log.d("Touch event received");
return false;
}
}
When I am on android 9, I am getting all touch events for my activity and log "Touch event received" getting print, but same is not the case with android 12.
I tried to change WindowManager.LayoutParams from
WindowManager.LayoutParams(0, 0, 0, 0, TYPE_APPLICATION, FLAG_NOT_FOCUSABLE|FLAG_NOT_TOUCH_MODAL|FLAG_WATCH_OUTSIDE_TOUCH, TRANSLUCENT)
To
WindowManager.LayoutParams(100, 100, 0, 0, TYPE_APPLICATION, FLAG_NOT_FOCUSABLE|FLAG_NOT_TOUCH_MODAL|FLAG_WATCH_OUTSIDE_TOUCH, TRANSLUCENT)
note the height and width has been changed to 100 x 100. This change worked and touch events are started working on android 12. My question is why zero height and width view was working on android 9 and not working on android 12? I could not find any change documented by google. Please help to identify the reason for this behavior change from 9 to 12.
Upvotes: 0
Views: 18