Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: system overlay

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?

like image 559
VKDev Avatar asked Feb 27 '15 10:02

VKDev


1 Answers

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

like image 78
Ashvin solanki Avatar answered Oct 02 '22 21:10

Ashvin solanki