Slide 1

Slide 1 text

Overlay Windows draw over the apps

Slide 2

Slide 2 text

Tato Kutalia tatocaster tatocaster.me github.com/tatocaster twitter.com/@tatokutalia

Slide 3

Slide 3 text

SYSTEM OVERLAY WINDOW

Slide 4

Slide 4 text

SYSTEM OVERLAY WINDOW • SYSTEM_ALERT_WINDOW permission • extend Service class • add view to Window Manager

Slide 5

Slide 5 text

SYSTEM_ALERT_WINDOW • granted automatically if installed from Play Store for 6.0 and up

Slide 6

Slide 6 text

SYSTEM_ALERT_WINDOW • Settings -> Apps -> Draw over other apps below 6.0 OR new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + packageName));

Slide 7

Slide 7 text

Service Class • extend service • inflate or use custom / compound views • add to window manager service getSystemService(Context.WINDOW_SERVICE) • service stops immediately after activity destroy

Slide 8

Slide 8 text

persistent service • return START_STICKY; always • and startForeground(int FOREGROUND_ID, Notification notification); those parameters allow to stay service alive and no matter what will persist over the top of apps // this will cause to show notification in status bar as long as the service retains. you can set pendingIntent to bind some actions on it

Slide 9

Slide 9 text

some things to know we should pass WindowManager.LayoutParams along the actual view to the window manager service. WindowManager.LayoutParams windowLayoutParams = new WindowManager.LayoutParams(
 CANVAS_WIDTH,
 CANVAS_HEIGHT,
 WindowManager.LayoutParams.TYPE_PHONE,
 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
 PixelFormat.TRANSLUCENT);
 windowLayoutParams.gravity = Gravity.BOTTOM | Gravity.END;
 with incorrect parameters, service may block touch events for lower app in view hierarchy (because our service is on top), even keyboard will not work. https://developer.android.com/reference/android/view/ WindowManager.LayoutParams.html

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Some Examples https://github.com/tatocaster/SnowViewChatHead https://github.com/tatocaster/BuildNumberOverlay