I have seen: WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY
always in combination with <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
in AndroidManifest.xml
. For example here.
Consider this code:
windowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
surfaceView = new SurfaceView(this);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
100, 100,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT
);
layoutParams.gravity = Gravity.START | Gravity.TOP;
windowManager.addView(surfaceView, layoutParams);
Do i need for this code SYSTEM_ALERT_WINDOW
permissions?
From doc about SYSTEM_ALERT_WINDOW
:
Allows an app to create windows using the type TYPE_SYSTEM_ALERT, shown on top of all other apps. Very few apps should use this permission; these windows are intended for system-level interaction with the user.
It's about TYPE_SYSTEM_ALERT
not about TYPE_SYSTEM_OVERLAY
. Hm?
UPDATE:
line: windowManager.addView(surfaceView, layoutParams);
java.lang.RuntimeException: Unable to create service: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@10dca8ac -- permission denied for this window type
So probably <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
is necessary.
ChangeWindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY
to WindowManager.LayoutParams.TYPE_TOAST
.android.permission.SYSTEM_ALERT_WINDOW
removed from Apps settings and it works.
Inspired: here
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
100, 100,
WindowManager.LayoutParams.TYPE_TOAST,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT
);
It seems that this solution do not need android:name="android.permission.SYSTEM_ALERT_WINDOW"
UPDATELayoutParams.TYPE_TOAST
is deprecated from API 26. Use LayoutParams.TYPE_APPLICATION_OVERLAY
instead and it is requires android.Manifest.permission#SYSTEM_ALERT_WINDOW
permission => See more
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