There is a View#onFilterTouchEventForSecurity()
method you can override to detect if the motion event has the FLAG_WINDOW_IS_OBSCURED
. This will let you know if something is drawn on top of your view.
@Override
public boolean onFilterTouchEventForSecurity(MotionEvent event) {
if ((event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) == MotionEvent.FLAG_WINDOW_IS_OBSCURED){
// show error message
return false;
}
return super.onFilterTouchEventForSecurity(event);
}
If you just want to protect your app from tap jacking due to another app drawing over your app you can add setFilterTouchesWhenObscured
to your views via XML or programmatically.