How to Overlay screen?
Android 4.0 +
public class MyService extends Service {
@Override
public void onCreate() {
super.onCreate();
WindowManager.LayoutParams params = ViewUtils.generateFullScreenParams(true);
final WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(overlayView, params);
}
...
}
and layout params creator
public static WindowManager.LayoutParams generateFullScreenParams() {
return new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
}
ok, looks good.
Flag TYPE_SYSTEM_ALERT not overlays the system bar (android < 5.0), not overlays soft buttons, but I can to handle onTouch event
Flag TYPE_SYSTEM_OVERLAY overlays the system bars, not overlays buttons and I can't to handle onTouch event.
Any ideas?
public static WindowManager.LayoutParams generateFullScreenParams() {
return new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
}
in This Code You added WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
remove this line its works and add touch event on view its works
For The Screen Overlay permission I am Referring to this post How to enable screen overlay permission by default
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With