Reputation: 4900
I've seen a couple of apps that are able to add overlay views from an accessibility service that are visible when the Settings app is on the foreground on also on the lock screen (!!).
I have implemented adding overlays but they are automatically hidden when the Settings app is in the foreground and on lock screen. I need to implement that for my app as well.
Anyone has any information on how to achieve that?
Upvotes: 3
Views: 1401
Reputation: 4900
So I found the answer. The way to do it is use an accessibility service and add the overlay view through that service and use the TYPE_ACCESSIBILITY_OVERLAY for the type parameter in the WindowManager.LayoutParams.
params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH|
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
Upvotes: 0
Reputation: 485
One way of doing this with Window Manager, TYPE_SYSTEM_OVERLAY.
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
View overlayView = LayoutInflater.from(this).inflate(R.layout.overlay_layout, null);
wm.addView(overlayView, params);
Create an overlay_layout.xml file for the overlay view.
Upvotes: 0