Monday, September 17, 2018

Android: system overlay

Leave a Comment

How to Overlay screen?

  1. it should be touchable
  2. view must overlay system action bar
  3. view must overlay soft buttons back/home/recent_apps
  4. 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?

1 Answers

Answers 1

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 Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment